Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- struct thread_args {
- int number;
- int number2;
- int operator_number;
- thread::id producer_tid;
- int id;
- };
- static volatile int producer_count = 0;
- static volatile int consumer_count = 0;
- static volatile int max_amount = 0;
- static thread_args the_args[10000000];
- static volatile int queue_amount = 0;
- mutex producer_mutex;
- mutex consumer_mutex;
- void producer(int operation_amount, int queue_limit) {
- int local_count = 0;
- while (true) {
- //iterator through the thread code until it is done
- if (max_amount > producer_count) {
- //check to make sure the max isn’t exceeded
- if (local_count <= operation_amount) {
- if (queue_amount < queue_limit) {
- producer_mutex.lock();
- thread_args arg;
- arg.number = rand();
- arg.number2 = rand();
- arg.operator_number = rand() % 4;
- arg.producer_tid = this_thread::get_id();
- arg.id = producer_count;
- the_args[producer_count] = arg;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement