Skip to content

Instantly share code, notes, and snippets.

@AlexsJones
Created September 6, 2012 14:40
Show Gist options
  • Select an option

  • Save AlexsJones/3656951 to your computer and use it in GitHub Desktop.

Select an option

Save AlexsJones/3656951 to your computer and use it in GitHub Desktop.
example of threading
#include <iostream>
#include <jnx_headers/jnxlib.hpp>
#include <queue>
#include <sstream>
#include <vector>
using namespace std;
using namespace jnx;
void *worker(void*ptr)
{
while(true) {
cout <<"I'm the first thread!" << endl;
sleep(1);
} ;
}
void *worker_two(void*ptr)
{
while(true)
{
cout << "Where as I am actually the second thread!" << endl;
sleep(1);
}
}
int main(int argc, char **argv) {
cout << "spawn thread" << endl;
jnx_thread *thread = jnx_threadmanager::create_thread("thread_one");
thread->start(worker);
int count = 0;
while(count <2)
{
++count;
sleep(1);
}
jnx_threadmanager::destroy_thread("thread_one");
sleep(1);
cout << "Destroyed first thread and the threadpool should be set to "<< jnx_threadmanager::get_thread_count() << endl;
jnx_thread *thread_two = jnx_threadmanager::create_thread("thread_two");
thread_two->start(worker_two);
sleep(3);
jnx_threadmanager::destroy_thread("thread_two");
cout << "Destroyed second thread and threadpool should be set to " << jnx_threadmanager::get_thread_count() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment