{"id":65,"date":"2012-04-15T13:28:41","date_gmt":"2012-04-15T13:28:41","guid":{"rendered":"http:\/\/finaldie.com\/wordpress\/?p=65"},"modified":"2012-04-15T13:35:45","modified_gmt":"2012-04-15T13:35:45","slug":"which-kind-of-multiple-threads-program-we-need-to-write","status":"publish","type":"post","link":"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/","title":{"rendered":"Which kind of multiple threads program we need to write"},"content":{"rendered":"<h1>SUMMARY<\/h1>\n<p>I think about this for a long time, and I have read lots of programs, which contain single thread or multiple threads. In my \u00a0opinion, some of them are not very good, that is why I write this blog.<\/p>\n<h1>SINGLE THREAD<\/h1>\n<p>Single thread program is simple for us, there is no lock to care, at most we only need to care about\u00a0asynchronous call.\u00a0\u00a0And we can provide a high\u00a0performance\u00a0program.<\/p>\n<h1>MULTIPLE THREADS<\/h1>\n<p>Multiple threads program is hard for us, there are lots of locks to care, we need to process them carefully, it&#8217;ll crash or dead lock when even one case of a wrong way to use lock. So, normally we need to do lots of efforts to debug and fix the bugs. Other wise, it maybe provide more performance than single program.\u00a0Actually I said &#8220;<strong>maybe<\/strong>&#8220;, you know there is no free\u00a0lunch\u00a0in many\u00a0scenes, that means we can&#8217;t get satisfied with the results normally.<\/p>\n<h1>WHY<\/h1>\n<p>I know many guys can not approve that, you maybe believe that multiple threads program can be really better than single one. Ok, we need to make a deep thinking, Does the multiple threads program just only add some threads into program simply? And you think the performance will be grow up simply? The answer is\u00a0obviously not. We know in many scenes we need to use the lock to\u00a0synchronous\u00a0our logic, whose resources share with other threads at the same time. When we entry the lock, the program will transfer to a single type program, so the performance will fall down, it will be even worse than the single thread one because of the lock call.<\/p>\n<p>You may say &#8220;there are lots of lock type suck as Read-Write Lock&#8221;. Yes, but read-write lock is only used for some special cases, and usually these cases are very limited.<\/p>\n<p>So the scene if you can separate logic into independence\u00a0parts, that&#8217;s a good scene and design. but if you can not separate completely, maybe you need to figure it out whether you should do it. For the second one, you may use lots of lock to protect your program for running well, but it&#8217;ll make it too complex and risk.<\/p>\n<p>But, another scene you can use multiple threads simply, that&#8217;s when your program has more than one part, and these parts are not the same functional, and then you can connect them easily, such as one producer one consumer model.<\/p>\n<h1>CONCLUSION<\/h1>\n<p>Ok, now you know whether you can decide what kind of program you need to use multiple threads.<\/p>\n<ul>\n<li>When the parts of program is the independence.<\/li>\n<li>one producer one consumer model.<\/li>\n<\/ul>\n<p>For other case, you need to figure it out and redesign for make the parts of your program independence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SUMMARY I think about this for a long time, and I have read lots of programs, which contain single thread or multiple threads. In my \u00a0opinion, some of them are not very good, that is why I write this blog. SINGLE THREAD Single thread program is simple for us, there is no lock to care, &#8230; <a title=\"Which kind of multiple threads program we need to write\" class=\"read-more\" href=\"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/\" aria-label=\"More on Which kind of multiple threads program we need to write\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Which kind of multiple threads program we need to write - Final Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Which kind of multiple threads program we need to write - Final Blog\" \/>\n<meta property=\"og:description\" content=\"SUMMARY I think about this for a long time, and I have read lots of programs, which contain single thread or multiple threads. In my \u00a0opinion, some of them are not very good, that is why I write this blog. SINGLE THREAD Single thread program is simple for us, there is no lock to care, ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/\" \/>\n<meta property=\"og:site_name\" content=\"Final Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hu.yuzhang\" \/>\n<meta property=\"article:published_time\" content=\"2012-04-15T13:28:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-04-15T13:35:45+00:00\" \/>\n<meta name=\"author\" content=\"final\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hyzwowtools\" \/>\n<meta name=\"twitter:site\" content=\"@hyzwowtools\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"final\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/\",\"url\":\"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/\",\"name\":\"Which kind of multiple threads program we need to write - Final Blog\",\"isPartOf\":{\"@id\":\"https:\/\/finaldie.com\/blog\/#website\"},\"datePublished\":\"2012-04-15T13:28:41+00:00\",\"dateModified\":\"2012-04-15T13:35:45+00:00\",\"author\":{\"@id\":\"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3\"},\"breadcrumb\":{\"@id\":\"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/finaldie.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Which kind of multiple threads program we need to write\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/finaldie.com\/blog\/#website\",\"url\":\"https:\/\/finaldie.com\/blog\/\",\"name\":\"Final Blog\",\"description\":\"As simple as possible...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/finaldie.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3\",\"name\":\"final\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/finaldie.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g\",\"caption\":\"final\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Which kind of multiple threads program we need to write - Final Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/","og_locale":"en_US","og_type":"article","og_title":"Which kind of multiple threads program we need to write - Final Blog","og_description":"SUMMARY I think about this for a long time, and I have read lots of programs, which contain single thread or multiple threads. In my \u00a0opinion, some of them are not very good, that is why I write this blog. SINGLE THREAD Single thread program is simple for us, there is no lock to care, ... Read more","og_url":"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/","og_site_name":"Final Blog","article_publisher":"https:\/\/www.facebook.com\/hu.yuzhang","article_published_time":"2012-04-15T13:28:41+00:00","article_modified_time":"2012-04-15T13:35:45+00:00","author":"final","twitter_card":"summary_large_image","twitter_creator":"@hyzwowtools","twitter_site":"@hyzwowtools","twitter_misc":{"Written by":"final","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/","url":"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/","name":"Which kind of multiple threads program we need to write - Final Blog","isPartOf":{"@id":"https:\/\/finaldie.com\/blog\/#website"},"datePublished":"2012-04-15T13:28:41+00:00","dateModified":"2012-04-15T13:35:45+00:00","author":{"@id":"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3"},"breadcrumb":{"@id":"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/finaldie.com\/blog\/which-kind-of-multiple-threads-program-we-need-to-write\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/finaldie.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Which kind of multiple threads program we need to write"}]},{"@type":"WebSite","@id":"https:\/\/finaldie.com\/blog\/#website","url":"https:\/\/finaldie.com\/blog\/","name":"Final Blog","description":"As simple as possible...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/finaldie.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3","name":"final","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/finaldie.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g","caption":"final"}}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts\/65"}],"collection":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":3,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions\/67"}],"wp:attachment":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}