/* This program has NUMBER_OF_PROCS processes executing the same function (MyJob()) at the same time, on the same shared variable (SharedCounter). Each process increments the variable a MAX_COUNT number of times. Runs on SGI machines runnning IRIX 5.3 (not sure about others). Compile: cc share.c -o share where share.c if the name of this file and share will be the name of the executable. Run: share at the prompt (the prompt is most likely % if you have a C or a C like shell, or $ if you have one of the other shells). */ #include #include #include #include #define errprint(S) fprintf(stderr, "*** %s\n", S); #define NUMBER_OF_PROCS 2 #define MAX_COUNT 1000000 #define MAX_TRIES 1000 /* data visisble by all processes that will be spawn. */ int SharedCounter=0; /* Here goes the code that will be concurently executed by processes. MyJob() increments the SharedCounter global variable a MAX_COUNT number of times. */ void MyJob() { int i; for (i=0; i