{"id":148,"date":"2006-03-12T21:36:00","date_gmt":"2006-03-13T05:36:00","guid":{"rendered":"http:\/\/eschatologist.net\/blog\/?p=148"},"modified":"2009-02-03T20:45:47","modified_gmt":"2009-02-04T04:45:47","slug":"cooperative-user-threads-vs-preemptive-kernel-threads","status":"publish","type":"post","link":"https:\/\/eschatologist.net\/blog\/?p=148","title":{"rendered":"Cooperative User Threads vs. Preemptive Kernel Threads"},"content":{"rendered":"<p><a href=\"http:\/\/www.cincomsmalltalk.com\/blog\/View.ssp\">James Robertson<\/a>, <cite><a href=\"http:\/\/www.cincomsmalltalk.com\/blog\/blogView?showComments=true&#038;entry=3319612045\">Cooperative Threading<\/a><\/cite>:<\/p>\n<p>> Well, in Cincom Smalltalk, this model gives you predictability &#8211;<br \/>\n> you know exactly what a thread is going to do. The issue with runaway<br \/>\n> threads rarely comes up for a simple reason &#8211; most processes end up<br \/>\n> pausing for I\/O (user input, db access, file access, sockets &#8211;<br \/>\n> what have you). That wait for I\/O state is what prevents a problem<br \/>\n> from arising.<\/p>\n<p>This is a classic problem and I&#8217;m honestly surprised to find out that Cincom Smalltalk implements cooperative user-level threads rather than supporting preemptive kernel threads.<\/p>\n<p>Here&#8217;s what I posted in response to James, unattributed thanks to the torturous comment interface on his blog:<\/p>\n<p>> One issue with cooperative threads relative to preemptive<br \/>\n> OS-supplied threads is that you get far less opportunity<br \/>\n> for true concurrency within an application. In an era when<br \/>\n> multi-core processors are becoming significantly more common,<br \/>\n> this is becoming exceptionally important to application<br \/>\n> developers. It&#8217;s not just about doing I\/O concurrently with<br \/>\n> other operations or allowing an application to perform<br \/>\n> multiple tasks at once; it&#8217;s about allowing a task to be<br \/>\n> completed faster because more efficient use is being made<br \/>\n> of machine resources. This is why I take an extremely<br \/>\n> skeptical view of user-level threading packages, especially<br \/>\n> in software built on platforms that have reasonable<br \/>\n> kernel-level threading.<\/p>\n<p>You&#8217;ll note that the various threading APIs in Mac OS X are all built on kernel threads.<\/p>\n<p>Furthermore, the Mach microkernel schedules exclusively in terms of threads.  The microkernel doesn&#8217;t even have a conception of processes!  It only knows about collections of resources \u00e2\u20ac\u201d *tasks* \u00e2\u20ac\u201d such as address spaces and IPC ports, and flows of control \u00e2\u20ac\u201d *threads* \u00e2\u20ac\u201d that it can schedule on processors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>James Robertson, Cooperative Threading: > Well, in Cincom Smalltalk, this model gives you predictability &#8211; > you know exactly what a thread is going to do. The issue with runaway > threads rarely comes up for a simple reason &#8211; most processes end up > pausing for I\/O (user input, db access, file access, sockets&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3],"tags":[4,22,38,120],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-technology","tag-mac","tag-programming","tag-smalltalk","tag-threads"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p74loH-2o","_links":{"self":[{"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=148"}],"version-history":[{"count":3,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":151,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions\/151"}],"wp:attachment":[{"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}