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 6186893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:58:04+00:00 2026-05-24T01:58:04+00:00

I am trying to write a simple lock/unlock algorithm that behaves like a mutex

  • 0

I am trying to write a simple lock/unlock algorithm that behaves like a mutex in distributed systems with C++.

It will be implemented as a library and users will be able to use it using the interface file.

Assume there are 3 processes {A,B,C}.

Each processors knows other processes’ addresses and ports and so on.

If A wants to lock on some object, it has get permission from other processes, which in this case B and C.

I believe sending and waiting for replies from B, and C won’t be a problem, because user will definitely call the function.

But, how should B, and C receive the message?

It is guaranteed that all processes will be alive.

Should there be a separate thread for each processor running listening(polling) to the sockets?

Does that mean if I create a thread in the constructor, and use it while the process is running, and destroying it at the destructor will be just fine?

  • 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-05-24T01:58:05+00:00Added an answer on May 24, 2026 at 1:58 am

    Should there be a separate thread for each processor running
    listening(polling) to the sockets?

    You should use a library for Inter-Process Communication, unless you intend to build something like that from scratch as an excercise. If you want to build something yourself, read that wikipedia article and maybe some chapters from books on Operating Systems (like Tanenbaum or Silberschatz).

    For your specific problem of mutual exclusion in distributed systems, see Maekawa’s Algorithm.

    Does that mean if I create a thread in the constructor, and use it
    while the process is running, and destroying it at the destructor will
    be just fine?

    If you plan to implement it like that, why not. Distributed systems often use a layered approach (see
    http://www.erlang.org/course/error_handling.html in an Erlang tutorial for example). A layer is essentially a collection of communicating and cross-dependent processes, that work together towards a common goal. One of those processes can act as the connection to a lower layer and another process as a connection to a higher layer. You could implement the complete layer in one operating system process using threads, that get created upon process creation and destroyed when destroying the process. It all depends on what you want to achieve and which path you take.

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

Sidebar

Related Questions

I'm trying to write a simple ruby script that will copy a file to
I'm trying to write a simple script that will list the contents found in
I am trying to write a simple if statement in javascript (jquery library) that
I'm trying to write simple DAO that will create entity objects based on their
I'm trying to write a simple javascript function that will clone some html input
I'm trying to write a simple program in VC++ which will just initialize the
I'm trying to write a simple WPF app that has two ellipses, joined by
I am trying to write a simple tool using Shoes. This will indent code
I'm trying write a simple perl script that reads some fields from a password
I am trying to write a simple program that lets me overlay a dot

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.