Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions