Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8286099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:37:43+00:00 2026-06-08T11:37:43+00:00

I am using queue for communication between two threads ( one just producing instance

  • 0

I am using queue for communication between two threads ( one just producing instance of custom class and pushes pointer to queue, other read from queue pointer on custom class and make some calculations). How to make push and pop on queue atomic, how to lock those operations ?( I cannot use C++11 standard )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:37:44+00:00Added an answer on June 8, 2026 at 11:37 am

    Probably the most portable non-C++11 locking mechanism is are the synchronisztion types from the Boost.Thread library. In particular the mutex class gives you a simple lockable object for giving exclusive access to a resource. For example:

    #include <boost/thread/mutex.hpp>
    #include <queue>
    
    template <typename T>
    class locking_queue {
    public:
        void push(T const & value) {
            boost::mutex::scoped_lock lock(mutex);
            queue.push(value);
        }
    
        bool pop(T & value) {
            boost::mutex::scoped_lock lock(mutex);
            if (queue.empty()) {
                return false;
            } else {
                value = queue.front();
                queue.pop();
                return true;
            }
        }
    
    private:
        std::queue<T> queue;
        boost::mutex mutex;
    };
    

    Another advantage is that this is quite similar to the C++11 std::mutex class, which will make conversion quite straightforward if you decide to use that instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirment to have communication between two processes using message queues. One
I'm browsing source codes from two applications sharing one queue using MSMQ. The first
I am using the multiprocessing python module with Queue for communication between processes. Some
I have two threads. One threads reads requests and passes it to server using
I'm performing a simulation of a simple queue using SimPy . One of the
One way to have interprocess communication is through a (named) pipe between the processes.
I have this scenario: One client sends a message into a msmq queue instance
In this question , I asked about using queue's and threads in C#. I
I am using Queue.Priority class in python 2.7 as below q=Queue.PriorityQueue() q.put((2,second)) q.put((1,first)) q.put((3,third))
Before I roll my own Queue using NSMutableArray , I'd like to know if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.