Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes Linux Time Division Processes Or Threads
    primarykey
    data
    text
    <p>A prof once told us in class that Windows, Linux, OS X and UNIX scale on threads and not processes, so threads would likely benefit your application even on a single processor because your application would be getting more time on the CPU.</p> <p>I tried with the following code on my machine (which only has one CPU).</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;pthread.h&gt; pthread_t xs[10]; void *nop(void *ptr) { unsigned long n = 1UL &lt;&lt; 30UL; while(n--); return NULL; } void test_one() { size_t len = (sizeof xs) / (sizeof *xs); while(len--) if(pthread_create(xs+len, NULL, nop, NULL)) exit(EXIT_FAILURE); len = (sizeof xs) / (sizeof *xs); while(len--) if(pthread_join(xs[len], NULL)) exit(EXIT_FAILURE); } void test_two() { size_t len = (sizeof xs) / (sizeof *xs); while(len--) nop(NULL); } int main(int argc, char *argv[]) { test_one(); // test_two(); printf("done\n"); return 0; } </code></pre> <p>Both tests were identical in terms of speed.</p> <pre><code>real 0m49.783s user 0m48.023s sys 0m0.224s </code></pre> <p></p> <pre><code>real 0m49.792s user 0m49.275s sys 0m0.192s </code></pre> <p>This me think, "Wow, threads suck". But, repeating the test on a university server with four processors close to quadrupled the speed.</p> <pre><code>real 0m7.800s user 0m30.170s sys 0m0.006s </code></pre> <p></p> <pre><code>real 0m30.190s user 0m30.165s sys 0m0.004s </code></pre> <p>Am I overlooking something when interpreting the results from my home machine?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload