Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create 2 threads. The first thread is the consumer thread that consumes the data written to a shared memory buffer. The second thread is the

Create 2 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. Use a mutex semaphore and counting semaphores to coordinate when each thread can safely write or read to/from a common shared memory region.

./program where determines the overall size (multiple of 32) and total number of blocks (memsize/32) of the shared memory region. The argument 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 and counting semaphores and create both the producer and consumer threads then wait for both threads to finish.

The producer thread is to create 30 bytes of random data (0-255) then store the checksum (use the Internet checksum) in the last 2 bytes of the shared memory block. The producer is to do this ntimes synchronizing with the consumer.

The consumer thread is to read the shared memory buffer of 30 bytes, calculate the checksum based upon the 30 bytes 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 ntimes synchronizing each read with the producer.

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

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago