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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:03:15+00:00 2026-05-26T16:03:15+00:00

I’m writing a multithreaded program, which would crash when a particular exception was thrown.

  • 0

I’m writing a multithreaded program, which would crash when a particular exception was thrown. Having stripped out more and more of the code to find the problem, I’m now left with an extremely simple case which causes one of many different crashes, seemingly at random. I’m at a loss as to why it’s doing this.

Here’s the entire contents of the program as it stands:

#include <windows.h>

WINAPI DWORD threadFunc(LPVOID x) {
  while (true) {
    try {
      throw 1;
    } catch (...) {
    }
  }
  return 0;
}

int main(int argc, char *argv[]) {
  CreateThread(NULL, 0, threadFunc, NULL, 0, NULL);
  CreateThread(NULL, 0, threadFunc, NULL, 0, NULL);

  Sleep(1000);

  return 0;
}

As far as I can tell, the program crashes while trying to throw, but not necessarily the first time.

The errors I’m getting in debug mode are:

  • seg fault, with stack trace including:
    • 00403F70 _Unwind_SjLj_RaiseException(exc=0x474380) (../../../gcc-4.4.1/libgcc/../gcc/unwind.inc:113)
    • 00000000 0x004025f6 in __cxa_throw() (??:??)
    • 00401380 threadFunc(x=0x0) (D:\Software Projects\testcpp\main.cpp:6)
    • 7C80B729 KERNEL32!GetModuleFileNameA() (C:\WINDOWS\system32\kernel32.dll:??)
    • 00000000 0x00000000 in ??() (??:??)
  • Program exited with code 03

and running without the debugger:

  • “The instruction 0x something referenced memory at 0x something else“, sometimes once, sometimes twice (presumably for the second thread)
  • “Process returned -1073741819 (0xC0000005)”, which is an access violation
  • “This application has requested the Runtime to terminate it in an unusual way … Process returned 3 (0x3)”

I’m completely stumped as to what could be causing all these different errors in such a short program. Commenting out one of the CreateThreads stops any errors occurring, so it seems to be something to do with the interaction of multithreading and exception throwing.

I’m using 32-bit Windows XP SP3, and MinGW 4.4.1

Update

The problem seems to have been a bug in the compiler (which is TDM-2 mingw32 4.4.1 – I wasn’t aware of the TDM element when asking the question, but I don’t think it makes a difference). Having upgraded to version 4.6.1 instead, it all seems to work fine.

Thanks to all who contributed to this question.

  • 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-26T16:03:16+00:00Added an answer on May 26, 2026 at 4:03 pm

    Update Having clarified in the comments that the errors occur immediately, and not at process shutdown, the only remaining conclusions that I can see are that:

    1. This is a bug in the compiler/runtime.
    2. You are linking against a single threaded runtime, or perhaps need to initialize the runtime for multi-threading. You are calling CreateThread but some C++ runtimes require you to use a runtime supplied thread creation function.

    Your problem is probably that the exception handling runtime support is being unloaded whilst the threads are still active. The runtime will shut itself down when you exit the main function. I would have expected the runtime to be more robust than this, but there you go.

    I would expect that your problems would vanish if you made sure that all your threads had terminated before you exited your main function. This is good practise no matter what, you don’t want threads to be forcibly terminated under any circumstances.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
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
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am writing an app with both english and french support. The app requests
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.