{"id":2007,"date":"2014-01-15T00:27:15","date_gmt":"2014-01-14T20:27:15","guid":{"rendered":"http:\/\/nayarweb.com\/blog\/?p=2007"},"modified":"2014-01-15T00:28:50","modified_gmt":"2014-01-14T20:28:50","slug":"threading-in-c11","status":"publish","type":"post","link":"https:\/\/nayarweb.com\/blog\/2014\/threading-in-c11\/","title":{"rendered":"Threading in C++11"},"content":{"rendered":"<p>Threading is sooo easy in C++11. It&#8217;s done 1 single line :3<\/p>\n<p><code><br \/>\nthread t(&MeraClass::sayHi,this,\"Nayar\");<br \/>\n<\/code><\/p>\n<p>That&#8217;s it. Use t.join() anywhere you want it to complete \ud83d\ude00<\/p>\n<p>The first argument is the name of the function or method you want to call. Since i mostly code using Object Oriented Programming (OOP), i need to specify the class name then pass the object from which i&#8217;m creating the thread. Here could be the class:-<\/p>\n<pre><code>\r\nusing namespace std;\r\nclass MeraClass {\r\n\r\npublic:\r\n   MeraClass(){\r\n       thread t(&MeraClass::sayHi,this,\"Nayar\");\r\n       t.join();\r\n   }\r\n\r\n   void sayHi(string name){\r\n        cout &lt;&lt; \"Hi \"&lt;&lt; name &lt;&lt;endl;\r\n   }\r\n};\r\n<\/code><\/pre>\n<p>Hey Java, BURN!!!! 3:)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Threading is sooo easy in C++11. It&#8217;s done 1 single line :3 thread t(&#038;MeraClass::sayHi,this,&#8221;Nayar&#8221;); That&#8217;s it. Use t.join() anywhere you want it to complete \ud83d\ude00 The first argument is the name of the function or method you want to call. Since i mostly code using Object Oriented Programming (OOP), i need to specify the class &hellip; <a href=\"https:\/\/nayarweb.com\/blog\/2014\/threading-in-c11\/\" class=\"continue-reading\">Continue reading <span class=\"screen-reader-text\">Threading in C++11<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[14,84,180],"class_list":["post-2007","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c","tag-programming","tag-threads"],"_links":{"self":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2007","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/comments?post=2007"}],"version-history":[{"count":6,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2007\/revisions"}],"predecessor-version":[{"id":2013,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/2007\/revisions\/2013"}],"wp:attachment":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/media?parent=2007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/categories?post=2007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/tags?post=2007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}