Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program that creates two threads thread 1 and thread 2. Thread 1 printsexactly the following text in one and only one line

Write a C program that creates two threads thread 1 and thread 2. Thread 1 printsexactly the following text in one and only one line (including a new line at the end of thetext): "thread 1: ping thread 2". Thread 1 then uses conditional variable functions tosignal thread 2 and blocks on another conditional variable waiting to be signaled bythread 2. Thread 2, upon being unblocked by thread 1 signal will print exactly thefollowing text: "thread 2: pong! thread 1 ping received" including a newline at the end.Thread 2 will then proceed to print "thread 2: ping thread 1" and signal thread 1, uponreceiving this signal on its condition variable, thread 1 will print exactly: "thread 1: pong!thread 2 ping received". From now on the sequence will repeat until the user of theprogram issues Ctrl-C or send SIGINT to the process. Any deviation like adding extralines or text will result in zero grade. Any unclean exit like using exit() or _exit() directlyfrom the signal handler will likely cause no output to be flushed and hence result in zerograde. Not placing a new line in each thread text will result in zero. Please be very carefulin following instructions as your program will be graded by a script and there will be nore-grade option if you did not follow the instructions. Use only pthreads conditionvariables to synchronize the two threads. The strings above must be sent to stdout, notdoing so will result in zero grade.

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago