Skip to main content
gamedev.net
🔒 Locked

Why doesn't this work?

Started by smart_idiot Feb 22, 2005 at 11:33 PM 3 replies 400+ views
Original Post
smart_idiot
smart_idiot
Are there some obscure rules regarding exceptions and threads that I don't know about? The program crashes when I throw the logic error.

#include "windows.h"
#include <iostream>
#include <stdexcept>

void foo(void)
 {
  throw std::logic_error("Why does this line crash?!");
 }

DWORD WINAPI threadEntryPoint(LPVOID)
 {
  try
   {
    Sleep(500); // Kill some time. . .
    foo();
   }
  
  catch(const std::exception &error)
   {}
  
  return 0;
 }

int main()
 {
  HANDLE thread[4];
  DWORD id[4];
  
  for(int i=0; i<4; ++i)
   thread=CreateThread(0, 0, &threadEntryPoint, 0, 0, id+i);
  
  WaitForMultipleObjects(4, thread, TRUE, INFINITE);
  
  std::cout << "Done!" << std::endl;
  std::cin.get();
  
  return 0;
 }

Any insight would be appreciated.
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
smart_idiot
smart_idiot
I'm thinking this is compiler specific, so I'm going to add that I'm using GCC 3.4.2. There's probably some switch I need to use or something I need to define.
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
smart_idiot
smart_idiot
Okay, I needed to compile with -mthreads. That was simple enough. Well, if anyone else has this problem, now you know the answer.
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
smart_idiot
smart_idiot
Well, -mthreads worked well for fixorizing my stand alone executables, But now my dynamically loaded libraries aren't being loaded dynamically. Foobie.

I'll have to look into this tomorrow. Or would that be later today? Blah.
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

Topic Locked

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

Sign in to reply to this topic.