Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 507

The Producer-Consumer Problem (also known as the bounded-buffer problem) is a classical example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue.

2 votes
Accepted

A multi-thread Producer Consumer, where a Consumer has multiple Producers (C++17) - Part 2

Overview Normally a ThreadPool has a fixed number of threads. With a variable amount of work that is to be completed by the threads. You have gone the other way. You have as many threads as there is …
Loki Astari's user avatar
  • 96.6k
11 votes
Accepted

C++ lock free, single producer, single consumer queue

Design The problem with your implementation of pop() is that it can not be implemented in an exception safe manner (for any type of T). This is why the standard implementation implements this as two …
Loki Astari's user avatar
  • 96.6k
6 votes

Collaboration of the two functions through multithreading

Your consumer thread locks out the producer for extended periods of time. void ConsumeData() { while (true) { std::unique_lock<std::mutex> uniqueLock(mutex); conditionVariable.wait(uni …
Loki Astari's user avatar
  • 96.6k
0 votes

Notifying consumers when a producer is done

There is no need to manually unlock. void push(const T& item) { unique_lock<mutex> mlock(_mutex); _queue.push(item); mlock.unlock(); // This is not needed. _cv.notify_one( …
Loki Astari's user avatar
  • 96.6k
7 votes

Concurrent stack in C

Issues: Failed to check the return value of all these system calls: stack->storage = malloc(sizeof(void*) * stack->capacity); pthread_mutex_init(&stack->mutex, NULL); pthread_cond_init(&stack->empty_c …
Loki Astari's user avatar
  • 96.6k
5 votes

Producer consumer in C++11

Dead Lock Bug If the queue is empty and the consumer thread is waiting in the condition variable. If you Queue goes out of scope the main thread will enter the detructor and perform join(). At this p …
Loki Astari's user avatar
  • 96.6k
2 votes

Relaying stdin data from one thread to another

My main problem with this is that myqueue is exposed and easily accessible. This makes it very easy for somebody else to write some other code that uses myqueue without knowing that is potentially bei …
Loki Astari's user avatar
  • 96.6k
1 vote

Multiple producers accessing multiple shared queues by checking for space two times

Overview You should be using std::thread and family rather than pthread. The main reason is that these objects are exception aware and will do the correct thing when being destroyed. Moving on assumin …
Loki Astari's user avatar
  • 96.6k
31 votes

A multi-threaded Producer Consumer with C++11

Prefer Reference over Pointer Since the producer and consumer must have a buffer you should pass it by reference (rather than pointer). This also makes sure there is no confusion over ownership of th …
Loki Astari's user avatar
  • 96.6k
2 votes

Producer-consumer code

Check error status: Well the first thing you should do is check the error state of all system calls. From: sem_wait.html The sem_wait() function locks the semaphore referenced by sem by performi …
Loki Astari's user avatar
  • 96.6k
3 votes
Accepted

Producer - Consumer interaction

Definitely not optimal as you are holding locks longer than you need too. boost::unique_lock<boost::mutex> lk(_frameCacheMutex); /// Here create the data for cache... // You are creating d …
Loki Astari's user avatar
  • 96.6k
1 vote
Accepted

Boost Threads - Producer Consumer threads with synchronization

Your usage of the condition variable will probably work but is a-typical. This is what you basically have: while (1) { boost::mutex::scoped_lock lock(m); if (<Test OK>) { < …
Loki Astari's user avatar
  • 96.6k
1 vote

boost::thread producer consumer

Why do you insist on putting the '' on members. It makes them look so ugly. Also most identifiers beginning with '' are reserved so you need to be careful. If you must use decade old conventions (that …
Loki Astari's user avatar
  • 96.6k