preshing / cpp11-on-multicore

Various synchronization primitives for multithreaded applications in C++11.
zlib License
517 stars 102 forks source link

Lost Wakeup [windows] #4

Closed inspirit closed 9 years ago

inspirit commented 9 years ago

Hi,

this might be my app architecture flow but still i would like to check.

i have multiple threads. each has its own AutoResetEvent object.

threads are running while there is a job in some shared queue. if no job can be found. each goes to sleep: my_event.wait();

when i'm adding job i iterate through all threads: thread.event.signal(); so i dont check if thread is actually wait, i always call signal for all threads.

everything works just fine until the whole threading pool is destructed:

  1. i set shutdown = true;
  2. iterate all threads: thread.event.signal.
  3. wait for atomic number to be zero. initially it is equal to the number of threads.

the app hangs on last step because some threads did not exit, and so do not reduce thread count atomic variable. i wasnt able to reproduce it on Mac but it happens often on Windows machine...

inspirit commented 9 years ago

looks like my problem is due to detached threads state... Strangely enough i loose connection to detached threads when the app is terminating. seem like windows terminate them before my thread-pool class destructor got executed

preshing commented 9 years ago

Sounds like an issue that is specific to your project... Best of luck, man!