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

The Archive Base Latest Questions

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

We have 2 applications. One written in C# and the other in C++. We

  • 0

We have 2 applications. One written in C# and the other in C++. We need to maintain a counter (in memory) shared between these processes. Every time one of these applications start, it needs to check for this counter and increase it and every time the application shut-down it needs to decrease the counter. If the application has a crash or shut-down using task manager, we also need the counter to decrease.
We thought of using one of the OS synchronization objects like MUTEX.
My question: What kind of sync object is the best for cross process (when one is C# and the other C++)

Hope my question was clear.
Thank you very much,

Adi Barda

  • 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-13T17:04:58+00:00Added an answer on May 13, 2026 at 5:04 pm

    You might get away with named semaphore. Semaphore is basically a count, it is here to allow developers limit the number of thread/processes that are accessing some resource. Usually it works like that

    1. You create a semaphore with maximum count N.
    2. N threads call waiting function on it, WaitForSingleObject or similar and each of them go on without waiting. Each time internal semaphore counter goes down.
    3. N+1 thread also calls waiting function but because internal counter of our semaphore is 0 now, it has to wait.
    4. One of our first N threads releases the semaphore by calling ReleaseSemaphore function. This function increments internal counter of semaphore.
    5. Our waiting thread don’t have to wait now, so it resumes but semaphore counter goes back to 0.

    I don’t think this is how you want to use it though. So, instead, you should:

    1. Create named semaphore with initial counter set to zero.
    2. When application start, immediately release it, increasing the counter. You’ll get previous counter value during that call.
    3. When application ends, call WaitForSingleObject(hSemaphore, 0), decreasing the counter. 0 means you don’t want to wait.

    This is all quite easy.

    In C++

    //create semaphore
    HANDLER hSemaphore = CreateSemaphore(NULL, 0, BIG_NUMBER, "My cool semaphore name");
    //increase counter
    LONG prev_counter;
    ReleaseSemaphore(hSemaphore, 1, &prev_counter);
    //decrease counter
    WaitForSingleObject(hSemaphore, 0);
    

    In C#

    using System.Threading;
    //create semaphore
    Semaphore sem = new Semaphore(0, BIG_NUMBER, "My cool semaphore name");
    //increase counter
    int prev_counter = sem.Release(); 
    //decrease counter
    sem.WaitOne(0);
    

    Names and BIG_NUMBERs should be the same obviously.

    If this is not sufficient for your task, you will have to look into shared memory and lock access to it though named mutex, but that is a little bit more complicated.

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

Sidebar

Related Questions

I have two separated applications, one written in Java and other in Erlang. Both
I have just re-written the authentication for one of our internal web applications to
I have two window form applications written in C, one holds a struct consisting
I have started upgrading one of our internal software applications, written in ASP.NET Web
I have Application written with GWT 1.7. I have one page where I upload
I have web application written in java using Eclipse. It has just one servlet
I have an application consisting of different modules written in C++. One of the
In my application, I have two DLLs. One is written in C# and the
I have a flash application written in action script 2, and at one point
I have some unit tests I've written to test my Django application. One test

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.