Created
September 6, 2012 14:40
-
-
Save AlexsJones/3656951 to your computer and use it in GitHub Desktop.
example of threading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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