Question: Implement a solution to the critical section problem for 2 threads using mutex locks. Specifically, in pthreads using pthread mutex trylock. You will need to

Implement a solution to the critical section problem for 2 threads using mutex locks. Specifically, in pthreads using pthread mutex trylock. You will need to use pthread Unix thread calls to start up two threads from the main process. Remember that all global memory is shared among threads of a process. Both threads need to count to 2,500,000 which means a correct overall count is 5,000,000. Thread1 needs to be designed so that every time it sees (counter -> value%100) == 0 it increments counter -> value by 100. That counts for 100 individual updates. You also need to keep track of how many times this happens and report it. Use the POSIX implementation of threads. Use getrusage to time the code.

You will need to look at the pthread create, pthread join and threads manual pages.

A tutorial and the man pages are here: http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html

Information on trylock is here: http://man.yolinux.com/cgi-bin/man2html?cgi_command=pthread_mutex_lock

Write a C program to solve this problem.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!