Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions