Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Write a C program that creates two threads thread 1 and thread 2. Thread 1 prints exactly the following text in one and only one line (including a new line at the end of the text): "thread 1: ping thread 2". Thread 1 then uses conditional variable functions to signal thread 2 and blocks on another conditional variable waiting to be signaled by thread 2. Thread 2, upon being unblocked by thread 1 signal will print exactly the following 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, upon receiving 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 the program issues Ctrl-C or send SIGINT to the process. Any deviation like adding extra lines or text will result in zero grade. Any unclean exit like using exit() or _exit() directly from the signal handler will likely cause no output to be flushed and hence result in zero grade. Not placing a new line in each thread text will result in zero. Please be very careful in following instructions as your program will be graded by a script and there will be no re-grade option if you did not follow the instructions. Use only pthreads condition variables to synchronize the two threads. The strings above must be sent to stdout, not doing 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 with AI-Powered 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

Students also viewed these Databases questions