OS is Linux working with pthreads
I have two worker threads that run forever until the stop variable is true and the threads stop gracefully. Instead of waiting, both threads call pthread_cond_wait until the signal informs of a new task. The system is working well.
Please create a stream of information that will print some debugging information. The information stream will try to read and print information every 30 seconds. Part of this information I would like to be STATES of each work flow. Is it possible to determine if a thread is blocked in "pthread_cond_wait"? If the thread is expecting pthread_cond_wait, then STATE == waiting for else is done by STATE ==.
while ( (sharedvaluffer == 0) && (doneflag == 0) ) { pthread_cond_wait (&taks_added, &buffer); }
Of course we can do this, we have more code. We can add to the above snippet a global variable that indicates that the thread is blocked. Code can be executed
while ( (sharedvaluffer == 0) && (doneflag == 0) ) { lock; i_am_waiting = truel unlock pthread_cond_wait (&taks_added, &buffer); }
The question is whether there is an easier way to scale. Stack of pending thread
Thread 6 (Thread 0x40800940 (LWP 20732)): #0 0x00002ba4567a9326 in pthread_cond_wait@@GLIBC_2.3.2 () #1 0x00000000007ce2ed in worker(void*) () #2 0x00002ba4567a5193 in start_thread () from /lib64/libpthread.so.0 #3 0x00002ba458a82f0d in clone () from /lib64/libc.so.6
c linux pthreads
cateof
source share