Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. using namespace std;
  2.  
  3. struct thread_args {
  4. int number;
  5. int number2;
  6. int operator_number;
  7. thread::id producer_tid;
  8. int id;
  9. };
  10.  
  11. static volatile int producer_count = 0;
  12. static volatile int consumer_count = 0;
  13. static volatile int max_amount = 0;
  14. static thread_args the_args[10000000];
  15. static volatile int queue_amount = 0;
  16. mutex producer_mutex;
  17. mutex consumer_mutex;
  18.  
  19. void producer(int operation_amount, int queue_limit) {
  20. int local_count = 0;
  21. while (true) {
  22. //iterator through the thread code until it is done
  23. if (max_amount > producer_count) {
  24. //check to make sure the max isn’t exceeded
  25. if (local_count <= operation_amount) {
  26. if (queue_amount < queue_limit) {
  27. producer_mutex.lock();
  28. thread_args arg;
  29. arg.number = rand();
  30. arg.number2 = rand();
  31. arg.operator_number = rand() % 4;
  32. arg.producer_tid = this_thread::get_id();
  33. arg.id = producer_count;
  34. the_args[producer_count] = arg;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement