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 76317

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:39:16+00:00 2026-05-10T20:39:16+00:00

I have a thread that, when its function exits its loop (the exit is

  • 0

I have a thread that, when its function exits its loop (the exit is triggered by an event), it does some cleanup and then sets a different event to let a master thread know that it is done.

However, under some circumstances, SetEvent() seems not to return after it sets the thread’s ‘I’m done’ event.

This thread is part of a DLL and the problem seems to occur after the DLL has been loaded/attached, the thread started, the thread ended and the DLL detached/unloaded a number of times without the application shutting down in between. The number of times this sequence has to be repeated before this problem happens is variable.

In case you are skeptical that I know what I’m talking about, I have determined what’s happening by bracketing the SetEvent() call with calls to OutputDebugString(). The output before SetEvent() appears. Then, the waiting thread produces output that indicates that the Event has been set.

However, the second call to OutputDebugString() in the exiting thread (the one AFTER SetEvent() ) never occurs, or at least its string never shows up. If this happens, the application crashes a few moments later.

(Note that the calls to OutputDebugString() were added after the problem started occurring, so it’s unlikely to be hanging there, rather than in SetEvent().)

I’m not entirely sure what causes the crash, but it occurs in the same thread in which SetEvent() didn’t return immediately (I’ve been tracking/outputting the thread IDs). I suppose it’s possible that SetEvent() is finally returning, by which point the context to which it is returning is gone/invalid, but what could cause such a delay?

It turns out that I’ve been blinded by looking at this code for so long, and it didn’t even occur to me to check the return code. I’m done looking at it for today, so I’ll know what it’s returning (if it’s returning) on Monday and I’ll edit this question with that info then.

Update: I changed the (master) code to wait for the thread to exit rather than for it to set the event, and removed the SetEvent() call from the slave thread. This changed the nature of the bug: now, instead of failing to return from SetEvent(), it doesn’t exit the thread at all and the whole thing hangs.

This indicates that the problem is not with SetEvent(), but something deeper. No idea what, yet, but it’s good not to be chasing down that blind alley.

Update (Feb 13/09):
It turned out that the problem was deeper than I thought when I asked this question. jdigital (and probably others) has pretty much nailed the underlying problem: we were trying to unload a thread as part of the process of detaching a DLL.

This, as I didn’t realize at the time, but have since found out through research here and elsewhere (Raymond Chen’s blog, for example), is a Very Bad Thing.

The problem was, because of the way it was coded and the way it was behaving, it not obvious that that was the underlying problem – it was camouflaged as all sorts of other Bad Behaviours that I had to wade through.

Some of the suggestions here helped me do that, so I’m grateful to everyone who contributed. Thank you!

  • 0 0 Answers
  • 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. 2026-05-10T20:39:17+00:00Added an answer on May 10, 2026 at 8:39 pm

    Who is unloading the DLL and at what time is the unload done? I am wondering if there is a timing issue here where the DLL is unloaded before the thread has run to completion.

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

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 54k
  • Answers 54k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer with RequiredFieldValidator you can not add your custom code. you… May 11, 2026 at 7:24 am
  • added an answer Difficult to tell from such a brief description, but I… May 11, 2026 at 7:24 am
  • added an answer Instead of .slideDown() and .slideUp() try to use respectively: $(yourElementHere).stop().animate({… May 11, 2026 at 7:23 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.