Skip to main content
gamedev.net
🔒 Locked

CPP exceptions and multi threading?

Started by The C modest god 2 replies 1k views
Original Post
The C modest god
The C modest god
I dont understand how this works. For instance, I had the main thread create another thread. If the main thread throws an exception, then both the main thread and the second thread catch this exception. However, if the second thread throws an excpetion, then only the second thread catchs the exception, but the main thread continues as usual. Is this true? What if I have more then two threads? how does it works? Thanks in advance.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
smart_idiot
smart_idiot
The exception should only be caught by the thread it was thrown in, since it involves unwinding the stack and each thread has its own stack independent of all the other threads. Since they're independant, it can't run into another thread's try/catch blocks while unwinding.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
Evil Steve
Evil Steve
I'm going to go and guess that the exception in the second thread causes something odd to happen in your main thread, which throws a seperate exception.
cnstrnd
cnstrnd
As stated by smart_idiot, exception mechanisms are not related to threading issues. The bug lies somewhere else.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.