The multithreading model

Again, here's what we do: it's key to understand that the code used here (ch14/speed_multiprcs_vs_multithrd_simple/create_destroy/pthread_test.c), is equivalent in all respects to the previous code except that here we work with threads and not processes: in a loop (that executes a total of 60,000 times!), create and destroy a thread by calling pthread_create(3) and subsequently pthread_exit(3). (We take care of details such as waiting in the calling thread for the sibling thread to terminate by invoking pthread_join(3).) As mentioned earlier, let's skip the code/API details for now and just see the execution:

$ time ./pthread_test real    0m3.584suser    0m0.379ssys     0m2.704s$ 

Wow, the threaded code has run approximately ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.