{"id":7393,"date":"2020-06-15T15:01:51","date_gmt":"2020-06-15T15:01:51","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=7393"},"modified":"2025-08-12T10:01:35","modified_gmt":"2025-08-12T10:01:35","slug":"threads-main-and-worker","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=7393","title":{"rendered":"Main thread vs. Worker thread(s)"},"content":{"rendered":"<h2>1. Main thread<\/h2>\n<p>&#8211; Gets created during startup<br \/>\n&#8211; It&#8217;s possibly the only thread<br \/>\n&#8211; Normally sets up the app\/program<br \/>\n&#8211; Often ends up in an event queue<\/p>\n<hr>\n<h2>2. Worker thread(s)<\/h2>\n<p>&#8211; Get spawned manually or borrowed from a pool<br \/>\n&#8211; Make it possible to solve tasks in parallel<br \/>\n&#8211; Release some load from the main thread<br \/>\n&#8211; Possibly work on an event\/task queue<\/p>\n<h3>2.1 Lifetime control<\/h3>\n<p>To control the lifetime of the spawned worker thread, &#8230;<br \/>\n&#8211; you can either use <b>join<\/b> to wait with the calling thread unit the spawned has finished its work &#8230;<br \/>\n&#8211; or you can <b>detach<\/b> it, and the system will clean up after the spawned thread has been finished.<\/p>\n<p>If a thread never gets detached or joined, it&#8217;s called a zombie thread.<\/p>\n<hr>\n<p>The following post contains a matching example: <a href=\"http:\/\/www.max-sperling.bplaced.net\/?p=19002\">Threading example with passive waiting (C++)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Main thread &#8211; Gets created during startup &#8211; It&#8217;s possibly the only thread &#8211; Normally sets up the app\/program<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[63],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/7393"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7393"}],"version-history":[{"count":5,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/7393\/revisions"}],"predecessor-version":[{"id":19006,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/7393\/revisions\/19006"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7393"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}