Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Q1.

Write a program that implements the following:

1. Define a global variable named total of type int.


2. Create 2 threads to represents students and all these threads implement Counts()
method.
3. Use pthread_join() function to suspend execution of the main thread.
4. implements Counts() method that adds one to the global variable total and prints the
thread ID and then the value of the variable total.
5. Add lock and unlock statements around the critical sections in Counts() method.
6. Compile and run the program.

5
1

1 Hind Alawfi
6

2 Hind Alawfi

You might also like