Question: 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
Get step-by-step solutions from verified subject matter experts
