lab4, producer/consumer fixed output
This commit is contained in:
@@ -5,18 +5,18 @@
|
||||
#ifndef CONSUMER_H
|
||||
#define CONSUMER_H
|
||||
|
||||
#include "buffer.h"
|
||||
#include <semaphore>
|
||||
|
||||
class Consumer {
|
||||
public:
|
||||
Consumer(int id, Buffer& buffer, std::counting_semaphore<5>& sem);
|
||||
void run() const;
|
||||
Consumer(int id, int read_fd, std::counting_semaphore<5>& consumerSem);
|
||||
void run(std::atomic<int>& itemsConsumed, const std::atomic<bool>& stopFlag) const;
|
||||
|
||||
private:
|
||||
int id;
|
||||
Buffer& buffer;
|
||||
std::counting_semaphore<5>& consumerSem;
|
||||
int consumerId;
|
||||
int readFd;
|
||||
std::counting_semaphore<5>& consumerSemaphore;
|
||||
};
|
||||
|
||||
#endif //CONSUMER_H
|
||||
#endif
|
||||
|
||||
|
||||
@@ -5,18 +5,17 @@
|
||||
#ifndef PRODUCER_H
|
||||
#define PRODUCER_H
|
||||
|
||||
#include "buffer.h"
|
||||
#include <semaphore>
|
||||
|
||||
class Producer {
|
||||
public:
|
||||
Producer(int id, Buffer& buffer, std::counting_semaphore<3>& sem);
|
||||
void run() const;
|
||||
Producer(int id, int write_fd, std::counting_semaphore<3>& producerSem);
|
||||
void run(std::atomic<int>& itemsProduced, const std::atomic<bool>& stopFlag) const;
|
||||
|
||||
private:
|
||||
int id;
|
||||
Buffer& buffer;
|
||||
std::counting_semaphore<3>& producerSem;
|
||||
int producerId;
|
||||
int writeFd;
|
||||
std::counting_semaphore<3>& producerSemaphore;
|
||||
};
|
||||
|
||||
#endif //PRODUCER_H
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user