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

  • SEARCH
  • Home
  • 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 8384319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:22:38+00:00 2026-06-09T17:22:38+00:00

I am building a multi-producer/single-consumer application using IPC, implemented using Boost.Interprocess . Each producer

  • 0

I am building a multi-producer/single-consumer application using IPC, implemented using Boost.Interprocess.

Each producer sends a message by allocating a block inside shared memory (managed_shared_memory::allocate), and marshalling an object into that block. Then, it sends a small object via a message_queue which holds the location (offset) of the block and the size.

The consumer receives this indicator from the queue and unmarshalls the object. The consumer is responsible for deallocating the block of memory.

Based on this implementation, I don’t believe the objects or blocks as they exist in memory need synchronisation, because as soon as the consumer knows about them, the producer will no longer touch them. Therefore, I believe it is only the internals of message_queue and managed_shared_memory which need synchronisation.

My question is: Bearing in mind that each process is single-threaded, do allocate/deallocate, and send/receive calls need synchronisation?

The Boost examples provided by the documentation don’t make use of synchronisation for the message queue, but I think this is only to simplify the sample source.


I have seen this question, but it is asking about thread-safety, and not about these specific components of Boost.Interprocess.

  • 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-09T17:22:39+00:00Added an answer on June 9, 2026 at 5:22 pm

    You do not need to use any kind of locking to protect these, operations. They are already protected using a recursive mutex in shared memory, otherwise multiple processes would not be able to operate in the same shared memory block at the same time.

    Regarding managed_shared_memory:

    One of the features of named/unique allocations/searches/destructions
    is that they are atomic. Named allocations use the recursive
    synchronization scheme defined by the internal mutex_family typedef
    defined of the memory allocation algorithm template parameter
    (MemoryAlgorithm). That is, the mutex type used to synchronize
    named/unique allocations is defined by the
    MemoryAlgorithm::mutex_family::recursive_mutex_type type. For shared
    memory, and memory mapped file based managed segments this recursive
    mutex is defined as boost::interprocess::interprocess_recursive_mutex.

    This also extends to raw allocation, you can verify this by looking at boost/interprocess/mem_algo/detail/simple_seq_fit.hpp.

    For message queue, boost::interprocess considers this to be a synchronization mechanism in the same way a mutex is, it will take care of all the necessary guarantees, locking its internal datastructures and issuing memory barriers as required.

    Furthermore this is all equally applicable to multithreaded programming. Even if you were calling send or allocate from multiple threads in the same program everything would be fine. The locking boost::interporcess provides would protect you from other threads in the same way it protects you from other processes.

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

Sidebar

Related Questions

We are building an ASP.Net MVC 2 multi-tenant application on SQL Server using the
I'm building multi tenant application with shared table structure using Microsoft SQL Server. I
I'm building a multi-threaded service application in Delphi XE2. Each thread serves its own
So imagine I'm building a Multi User Dungeon system using a MVC web application.
I'm building a multi-site Zend Framework application using modules, sort of in the following
I'm building a multi-tenant ASP .NET application. Given that each tenant can configure their
I am building a multi-user web application. Each user can have their own site
I have been building a multi threaded server, with each thread having a single
I'm building a multi-lingual website using drupal 7. Now, I'm in the process of
I am building a multi threading application. I have setup a threadPool. [ A

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.