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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:08:33+00:00 2026-06-05T16:08:33+00:00

I’m working on a project which involves two processes, let them be A and

  • 0

I’m working on a project which involves two processes, let them be A and B.
A has got two threads: T1 and T2.

A and B are run separately.

At a certain point T1 sends a message (it’s a COM call, a search request) to B. When B has processed some data it returns by sending the result (again, it’s a COM call, the search results) directly to T2.
I need T1 to block until T2 has processed B’s data.
So far I used the following solution:

Initialization:
searchSyncSempahore = ::CreateSemaphore(NULL, 0, 1, NULL);

T1:

B_handle->search(searchString);
::WaitForSingleObject(searchSyncSempahore, INFINITE);
// Use searchResult variable

T2:

searchResult = _some_data_from_B;
::ReleaseSemaphore(searchSyncSempahore, 1, NULL);

This works so far. It works even if B is so fast that T2 calls ReleaseSemaphore before T1 reaches the WaitForSingleObject line.

My problem is: what happens if B crashes? T1 will just wait for ever. I have to specify the timeout but if it’s too low when T2 receives results it will just screw up the semaphore, messing up the following search.

So how can I correctly synchronize these two threads taking into account that T2 could never be called (i.e. How can I implement “abort search”)?

  • 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-05T16:08:35+00:00Added an answer on June 5, 2026 at 4:08 pm

    The possible solution is to create a watchdog thread which will handling such situation using Manual-Reset events. So the logic will change a small: instead of waiting the mutex, you can wait for event. The watchdog thread than could check if the thread stuck for a long time, just set event by itself and could set an additional event saying that critical situation is appeared.
    I mean this third thread can act as a watchdog timer.

    The other variant is to use a Condition Variables in that third thread. So, you can simply kick one of the condition variables and it will wake up the thread waiting for it. I must admit, I’m not very familiar with this approach.

    UPDATE:
    Consider using a SignalObjectAndWait function. The function signals one object and waits on another object as a single operation. Also, you can set a wait timeout, and the function returns if the interval elapses, even if the object’s state is nonsignaled.

    Another benefit of using thread watchdog, that you can do additional stuff in it: logging to file or even in MS EventLog or can provide logic to change an application behaviour. One more example is that a watchdog thread can implement ‘thread redundancy’ capability.

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

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.