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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:57:45+00:00 2026-05-25T23:57:45+00:00

I would like to ask you a question regarding which concurrency facility (CMutex, CSemaphore,

  • 0

I would like to ask you a question regarding which concurrency facility (CMutex, CSemaphore, CEvent) should I choose, to make a C++/MFC, application multi-threaded.

It is a real time, machine vision application, that is required now to execute concurrently and it needs refactoring, from it’s previous single-threaded status.

A single iteration of my workflow is the following. I have 2 producers A,B (MFC Workers) that need to fill two separate data structures (1 each). A third thread, a consumer (MFC Worker as well) is blocked, until both data become available from A and B. Then, producers A and B must block (each, upon their data completion), C must wake up, perform a calculation, unblock A and B to continue and become blocked again, waiting for the next segments.

  1. I must not use queues (Actor-like) – the blocking is a requirement
    🙁
  2. I tried CEvent and it works. AutoResetEvents for A,B to unblock a
    CMultiLock call on C and then a ManualResetEvent->Set() from C, to
    unblock A and B waiting on the latter event. My concern is when to
    reset this event (in case e.g. A miss the whole Set and then Reset.)
  3. Do semaphores with plurality of 2 may stand for a better solution?

Best regards.

  • 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-25T23:57:46+00:00Added an answer on May 25, 2026 at 11:57 pm

    C must wait for two things to happen, so the most logical thing is that it waits for two auto-reset CEvent objects: one set by A and one by B.

    When C is done, A and B must each then wait for a notification. Since there are two threads, and both must wake up, the natural thing is to use another pair of auto-reset CEvent objects, one for each of A and B. C can then set both when it is done.

    A semaphore with a count of 2 would work for waking C — C waits twice, and each of A and B notify — but this means that C must wake up after the first notification in order to wait for the second, which is less than ideal.

    Using a semaphore with a count of 2 for waking A and B afterwards has the potential for stolen wake-ups and confusion. C signals the semaphore twice. A wakes and takes a signal, does its processing and notifies C, and then waits on the semaphore again. Since B hasn’t yet woken up, the semaphore is still available, so A takes it again. Meanwhile B is not stuck, since it won’t get another signal, and C is stuck, since it will wait for the next value from B.

    An alternative is to use the Windows Condition Variable API rather than events, but there doesn’t seem to be an MFC wrapper for that. See http://msdn.microsoft.com/en-us/library/ms682052%28VS.85%29.aspx

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

Sidebar

Related Questions

I would like to ask a rather, general, high-level introductory kind of question regarding
I am new to android I would like to ask a question which may
I would like to ask a question regarding a strange behavior I face using
I would like to ask couple of Questions regarding the use of Monitor Class
Just like Carl's question over here I would like to ask you (because I
I know this is a weird question to ask, but I would like to
I would like to ask you which automated build environment you consider better, based
I would like to ask a follow up question to an oldie (but goodie)
I would like to ask you a question about implementing mutual authentication with Kerberos,
I use c#, linq and EF4 I would like ask your help. My question:

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.