On 3/16/20 9:16 PM, silvioprog wrote: > On Mon, Mar 16, 2020 at 4:29 PM Christian Grothoff <groth...@gnunet.org > <mailto:groth...@gnunet.org>> wrote: > > This seems kind-of OK (I personally think pthread_detach is always messy > and in 99.9% of cases a bad idea). > > > Hm... Could you point the disadvantages of using detached threads? I'm a > little newbie with this feature of pthreads.
Usually, you will eventually find that you do need to wait on the thread to finish for a controlled shutdown, and at that point it is then better to keep the thread handles in some data structure so you can join. At least I found that to be virtually always the case when doing disciplined multi-threaded programming. But, this is certainly not fundamental, and you might be able to write perfectly correct programs with detached threads. Your existing approach, for example, does not seem to naturally support a clean shutdown of the process using CTRL-C / SIGTERM.
signature.asc
Description: OpenPGP digital signature