Answer the question
In order to leave comments, you need to log in
How to solve the "reader and writer" problem with a buffer pool (dynamic array)?
The task itself:
Consider the interaction of two threads, one of which writes data to the buffer pool, and the other reads them from the pool. The buffer pool consists of N buffers, each containing one entry. In the general case, the writer thread and the reader thread have different speeds (the duration of the read and write operation) and access the pool with variable intensity (they start performing operations at random times with a uniform distribution law). To work properly, the writer thread pauses when all buffers are full and wakes up when there is at least one free buffer. The reader thread is suspended when all buffers are empty and is reactivated when at least one entry has been received.
The number of writer and reader threads, the duration of read and write operations, and the size of the buffer pool are set by the user.
The buffer pool in this case is a dynamic array, if I understood the teacher correctly. By the condition of the task, the reader thread and the writer thread are suspended waiting for a non-empty and empty buffer, respectively.
How to implement a check for the presence of an empty-non-empty buffer so that streams are activated?
How to transfer the address of the freed buffer to the reader thread or the writer thread to work with it?
The basic principle of how threads work is similar to the example on wikipedia ( here ), but you can solve it with 2 semaphores.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question