Question: write a C program that creates two threads. The first thread is the consumer thread that consumes the data written to a shared memory buffer.

write a C program that creates two threads. The first thread is the consumer thread that consumes the data written to a shared memory buffer. The second thread is the producer thread that produces the data for the shared memory buffer. In order to prevent a race condition (e.g. the consumer reading before the producer writing) use a mutex semaphore to coordinate when each thread can safely write or read to/from a common shared memory region

Have the user tell you the value of two variables: ( mem1 ) determines the overall size of the shared memory region and ( ntim ) indicates the number of times the producer writes to and the consumer reads from the shared memory region.

The main process is to create the shared memory region from the heap based upon memsize, initialize the mutex semaphore and create both the producer and consumer threads then wait for both threads to finish. 3. The producer thread is to create mem1-4 bytes of random data (0-255) then store the CRC in the last 4 bytes of shared memory buffer.

The producer is to do this ntim times synchronizing each write with the consumer

The consumer thread is to read the shared memory buffer of mem1, calculate the CRC based upon the mem1 -4 and compare that with the value stored in the shared memory buffer to ensure that the data did not get corrupted. The consumer is to do this ntim times synchronizing each read with the produce

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!