Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This project will be to implement the proper synchronization between Producer and Consumer threads using Semaphore and Lock. Python has Semaphore and Lock which must

This project will be to implement the proper synchronization between Producer and Consumer threads using Semaphore and Lock.

Python has Semaphore and Lock which must be used to complete the implementation (https://docs.python.org/2/library/threading.html)

You must optimize your code, to minimize the duration at which the Lock is held by any of the thread.

The program has Producer and Consumer threads, which currently do not synchronize themselves between each thread of the same type and also between Consumer and Producer.

The program processes a file, which contain 3 fields per line: ,,.

The transaction must be processed in a FIFO manner between the producer and the consumer.

When a producer threads reads a transaction, it increments the idCounter, puts it in the FIFO, then sleeps the number of producer ms specified in the transaction.

When a consumer threads gets a transaction from the FIFO, it then sleep the number of consumer ms specified in the transaction before trying to obtain the next transaction from the FIFO.

What you must do:

synchronize between the producers the idCounter

synchronize between the producers, to have only one producer read from the file the next transaction and also to have them all stop if one of the thread has reached the end of file

synchronize between the producers and the consumers, to have the producer stop when the FIFO is full (based on the maxFifoDepth), or to have the consumers stops when the FIFO is empty

synchronize between the consumers and the producers, to have the consumer threads stop when the end of file is reached

test files: there is one transaction file as part of the assignment. You must create additional files that you will use to test your implementation under multiple scenarios to prove that the synchronization is correct (1 producer+N consumers, N producers+1 consumer, N producers+N consumers, changes in the sleep, ....) and provide the documentation regarding each of these tests

Grade:

synchronization between producers: 25

synchronization between producers and consumers: 25

synchronization on the end of file between producers: 25

test files and parameters: 15

documentation of the tests: 10

1st bonus: if on the 1st submission you have #1 synchronize between the producers the idCounter completed :10

2nd bonus: synchronization on the end of file between producers and consumers: 10

You must use Semaphone (to track the number of transaction in the fifo) and Lock (for the critical section) see: https://docs.python.org/2/library/threading.html.

See textbook p. 130 Solving the Producer-Consumer Problem using Semaphores

Submission:

One zip file per team, with the python implementation, the transaction files used to test your implementation and a documentation of the command line(arguments) used to test your program.

For each test you did, provide the command line and the output of the program.

Examples of test documentation:

Test # - Input filename - # of Producer - # of Consumer - Max FIFO Depth

1 - transaction.txt - 1 - 1 - 1

2 - transaction.txt - 1 - 2 - 5

.....

There is a startup implementation in python: project2.py and also an example of a transaction file: transaction.txt

Command line : project2.py <# of producer> <# of consumer>

As an example, to execute the program:

python project2.py transaction.txt 1 1 5

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

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

What is sampling with replacement, and why is it used?

Answered: 1 week ago

Question

What are the different forms of depositary receipt?

Answered: 1 week ago