Mycroft Holmes
2010-03-08 13:09:53 UTC
Hi all,
this is a question specific to windows.
we'd like to induce a running thread to throw an exception; the
following fragment should give the idea:
struct bomb_explosion {};
void explode()
{
throw bomb_explosion();
}
void compute_result()
{
TIME_BOMB t(60, &explode); // after 60 seconds, call "explode"
try
{
t.activate();
perform_a_long_operation();
}
catch(bomb_explosion&)
{
std::cout << "timeout!";
}
t.deactivate();
}
we were looking at the documentation of Timer Queues, but if we got it
right, when the timer invokes the callback, it runs as a different
thread, so a throw wouldn't work.
the naive approach would be: set a (global) variable inside the
callback, and periodically check it inside
"perform_a_long_operation"; however we cannot use this pattern,
because this last function is read-only for us.
is there any windows api/trick we can use?
TIA
-mh
this is a question specific to windows.
we'd like to induce a running thread to throw an exception; the
following fragment should give the idea:
struct bomb_explosion {};
void explode()
{
throw bomb_explosion();
}
void compute_result()
{
TIME_BOMB t(60, &explode); // after 60 seconds, call "explode"
try
{
t.activate();
perform_a_long_operation();
}
catch(bomb_explosion&)
{
std::cout << "timeout!";
}
t.deactivate();
}
we were looking at the documentation of Timer Queues, but if we got it
right, when the timer invokes the callback, it runs as a different
thread, so a throw wouldn't work.
the naive approach would be: set a (global) variable inside the
callback, and periodically check it inside
"perform_a_long_operation"; however we cannot use this pattern,
because this last function is read-only for us.
is there any windows api/trick we can use?
TIA
-mh