{"id":104,"date":"2006-07-25T17:08:36","date_gmt":"2006-07-25T21:08:36","guid":{"rendered":"http:\/\/www.rakkar.org\/blog\/?p=104"},"modified":"2006-07-25T17:08:36","modified_gmt":"2006-07-25T21:08:36","slug":"wrote-a-worker-thread-class","status":"publish","type":"post","link":"https:\/\/rakkar.org\/blog\/index.php\/2006\/07\/25\/wrote-a-worker-thread-class\/","title":{"rendered":"Wrote a worker thread class"},"content":{"rendered":"<p>\t\t\t\tPretty useful and easy to use.  You can cancel inputs before they are processed as well.<\/p>\n<p><code><br \/>\n#include \"WorkerThreads.h\"<br \/>\n#include \"RakSleep.h\"<br \/>\n#include <stdio .h><br \/>\n#include <conio .h><\/p>\n<p>void *func(void *input)<br \/>\n{<br \/>\n\tchar *val = (char*) input;<\/p>\n<p>\tprintf(\"%s\\n\", val);<br \/>\n\tRakSleep(2000);<br \/>\n\treturn (void*)(val[strlen(val)-1]);<br \/>\n}<\/p>\n<p>void main(void)<br \/>\n{<br \/>\n\tchar *strings[9] =<br \/>\n\t{\"String 1\",<br \/>\n\t\t\"String 2\",<br \/>\n\t\t\"String 3\",<br \/>\n\t\t\"String 4\",<br \/>\n\t\t\"String 5\",<br \/>\n\t\t\"String 6\",<br \/>\n\t\t\"String 7\",<br \/>\n\t\t\"String 8\",<br \/>\n\t\t\"String 9\"};<\/p>\n<p>\tWorkerThreads workerThreads;<br \/>\n\tworkerThreads.StartThreads(2, 0);<br \/>\n\tfor (int i=0; i < 9; i++)\n\t{\n\t\tworkerThreads.AddInput(func, strings[i]);\n\t}\n\tprintf(\"Input sends done\\n\");\n\tvoid *out;\n\twhile(!kbhit())\n\t{\n\t\tout=workerThreads.GetOutput();\n\t\tif (out)\n\t\t{\n\t\t\tprintf(\"Got output %i\\n\", (int) out);\n\t\t}\n\t}\n\tworkerThreads.EndThreads();\n}\n<\/code><\/conio><\/stdio><\/code>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pretty useful and easy to use. You can cancel inputs before they are processed as well. #include &#8220;WorkerThreads.h&#8221; #include &#8220;RakSleep.h&#8221; #include #include void *func(void *input) { char *val = (char*) input; printf(&#8220;%s\\n&#8221;, val); RakSleep(2000); return (void*)(val[strlen(val)-1]); } void main(void) { char *strings[9] = {&#8220;String 1&#8221;, &#8220;String 2&#8221;, &#8220;String 3&#8221;, &#8220;String 4&#8221;, &#8220;String 5&#8221;, &#8220;String 6&#8221;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/104"}],"collection":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=104"}],"version-history":[{"count":0,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"wp:attachment":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}