Main thread vs. Worker thread(s)

1. Main thread

– Gets created during startup
– It’s possibly the only thread
– Normally sets up the app/program
– Often ends up in an event queue


2. Worker thread(s)

– Get spawned manually or borrowed from a pool
– Make it possible to solve tasks in parallel
– Release some load from the main thread
– Possibly work on an event/task queue

2.1 Lifetime control

To control the lifetime of the spawned worker thread, …
– you can either use join to wait with the calling thread unit the spawned has finished its work …
– or you can detach it, and the system will clean up after the spawned thread has been finished.

If a thread never gets detached or joined, it’s called a zombie thread.


The following post contains a matching example: Threading example with passive waiting (C++)