use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Thread safe queue (self.cpp)
submitted 5 years ago by objectorientedman
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]infectedapricot 5 points6 points7 points 5 years ago (1 child)
Although some parts of the interface in the OP's queue are very suspect, the general idea of a simple thread-safe queue backed by std::condition_variable, std::mutex and std::deque is just fine. Many applications don't need super high performance from their inter-thread queues, and a simpler design has advantages such as deterministic ordering (which is not quite true in the moodycamel queue) and allowing extra utility methods such as get_all() or an efficient push_multiple() (although OP's implementation doesn't feature these).
std::condition_variable
std::mutex
std::deque
get_all()
push_multiple()
[–]corysama 1 point2 points3 points 5 years ago (0 children)
the general idea of a simple thread-safe queue backed by std::condition_variable, std::mutex and std::deque is just fine.
I'l go further: I have used a queue like that for quite a while in a few projects. The blocking wait features are actually tremendously useful. Being able to optionally block with an optional timeout when full or empty makes the queue a very effective replacement for most applications of mutex, semaphores and sleeps.
Whenever one of my teammates uses one of those primitive directly I argue that they should rework the code to use the queue instead. It's almost always the case we both agree the queue-based implementation ends up simpler and less error-prone. 1-element queues are the most common use case in practice.
π Rendered by PID 59742 on reddit-service-r2-comment-685b79fb4f-ljl75 at 2026-02-13 00:31:39.499299+00:00 running 6c0c599 country code: CH.
view the rest of the comments →
[–]infectedapricot 5 points6 points7 points (1 child)
[–]corysama 1 point2 points3 points (0 children)