|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-08-03 15:42:56
> In case I've not convinced you yet, here are two other core language
> issues with this approach.
>
> 1) If while processing an exception a local is destroyed whose
> destructor throws an exception, terminate will be called. (15.2/3)
>
> 2) Consider the following: void foo() throw() { bar(); }.
>
> What's needed is exception style stack unwinding with no possiblity
> of the user circumventing things.
what ?!
ever heard of Java's InterruptedException and
usage patterns like
25: public void stopRequestIdleWorkers() {
26: try {
27: Object[] idle = idleWorkers.removeAll();
28: for ( int i = 0; i < idle.length; i++ ) {
29: ( (ThreadPoolWorker) idle[i] ).stopRequest();
30: }
31: } catch ( InterruptedException x ) {
32: Thread.currentThread().interrupt(); // re-assert
33: }
8: return new Runnable() {
9: public void run() {
10: try {
11: System.out.println(name +": starting up");
12: Thread.sleep(firstDelay);
13: System.out.println(name + ": doing some stuff");
14: Thread.sleep(2000);
15: System.out.println(name + ": leaving");
16: } catch ( InterruptedException ix ) {
17: System.out.println(name + ": got interrupted!");
18: return;
19: } catch ( Exception x ) {
20: x.printStackTrace();
21: }
22: }
synchronized void waitForGameToEnd() {
while (gameInProgress()) {
try {
wait();
} catch (InterruptedException e) {
}
}
}
public class Task implements Runnable
{
public void run()
{
try{ doTask(); }
catch(InterruptedException e) { Sys.out("User cancelled."); }
}
public void doTask() throws InterruptedException
{
doMajorTask1();
checkInterrupted();
doMajorTask2();
checkInterrupted();
doMajorTask3();
}
public void checkInterrupted() throws InterruptedException
{
if(Thread.currentThread().isInterrupted())
throw new InterruptedException();
}
}
........
????
thread return value aside, thread::exit() should be equal
to this_thread->interrupt() / throw InterruptedException().
regards,
alexander.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk