Content
e Times located mem. y updates the ogram to see each running 100), and yet ently! It is as id of sharing is virtualiz dress space ehow maps ence within er processes it has phys memory is how all of ook, on the is concep adressed the same berating include "common.h" volatile int counter 0; int loops; void worker (void arg) int i; for (1 0; 1 10ops; 1) counter; return NULL; 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 int main (int arg, char argv ) if (argc ! 2) fprintf (stderr, "usage: threads value n"); exit (1); loops atoi (argv 1); pthreadt p1, p2; printf ("Initial value : dn", counter); Pthreadcreate ( 1, NULL, worker, NULL); Pthreadcreate (Sp2, NULL, worker, NULL); Pthread join (p1, NULL); Pthread join (p2, NULL); printf ("Final value :adn", counter); return 0; Figure 2.5: A Multi-threaded Program (threads. c) Unfortunately, the problems of concurrency are no longer lin to the OS itself. Indeed, modern multi-threaded programs ex same problems. Let us demonstrate with an example of a multi-t broaram (Figure 2 5) tand this example fully at the in later chapters, in the secti a is simple. The main prograr re () 6. You can think of a thi remory space as other functic me. In this example, each thre E () , in which it simply incr