|
General IRI utilities
|
This is an example on how to use the CThreadServer class
In this example threads are handled through the CThreadServer class instead of being directly handled by the user. The sequence of function calls is the same as when dealing with CThread objects, but the main difference is that all function calls are done through the CThreadServer class using the unique identifier of each thread.
The second thread starts over 2 seconds after the first one, and then the program waits for the second one to terminate before killing the first one. Notice that the threads are created by calling the create_thread() function with the desired unique identifier, and they must be destroyed by calling the destroy_thread() function. Otherwise they are kept in memory until the application ends.
The putput of this example should be something like this:
* thread 1 loop 0 * thread 1 loop 1 * thread 2 loop 0 * thread 1 loop 2 * thread 2 loop 1 * thread 1 loop 3 * thread 2 loop 2 * thread 1 loop 4 * thread 1 loop 5 * thread 2 loop 3 * thread 1 loop 6 * thread 2 loop 4 * thread 1 loop 7 * thread 2 loop 5 * thread 1 loop 8 * thread 2 loop 6 * thread 1 loop 9 * thread 2 loop 7 * thread 1 loop 10 * thread 2 loop 8 * thread 1 loop 11 * thread 2 loop 9 * thread 1 loop 12 * thread 2 loop 10 * thread 1 loop 13 * thread 2 loop 11 * thread 1 loop 14 * thread 2 loop 12 * thread 1 loop 15 * thread 2 loop 13 * thread 1 loop 16 * thread 2 loop 14 * thread 1 loop 17 * [Exception caught] - [CThread class] - The thread has not been attached to a function - thread_1 * [Exception caught] - [CThreadServer class] - Unknown thread - invalid_thread *
Several error may be thrown by the CThreadServer class:
1.8.6