[cpp-threads] pthreads cancellation

Doug Lea dl at cs.oswego.edu
Thu Apr 28 00:10:02 BST 2005


Andrei Alexandrescu wrote:
>
> 
> Also, speaking of thread cancellation, I propose (and I know this is a 
> hard-to-swallow proposal) that we don't include any API that forcefully 
> terminates a thread without that thread's cooperation. Threads are easy 
> to start but essentially unstoppable unless they're willing to.
> 

I don't think anyone will find this hard to swallow. "Killing
threads considered harmful" seems to have reached the common
wisdom stage.

However, our experience with java shows that people do very
much need some standaridzed notion of cancellation. ("task.cancel(...)"
means "I no longer need this task to be done", which is very different
than causing abrupt async exceptions etc.)

(Kevlin: I owe you a set of comment on the proposal you
posted last week, but one quick note about it
is that I think you need to tie in uniform task cancellation
support. Which  I think means that you don't want to
separate out joiners.)


> }
> 
> That also reminds me of something else. We need to define what the 
> threading behavior for various standard lib functions is, particularly 
> potentially blocking functions such as I/O. That is essential to writing 
> proper shutdown code.
 >

> 
> For example, we should specify that any file close operation in one 
> thread is causing immediate (time-bounded) termination of any I/O 
> operations on that file in any other thread, with an error. If sockets 
> will be also added to the standard library, we'd need to similarly 
> specify that closing a socket in a thread cancels with an error any 
> blocking operation on that socket.

Based again on Java experience, this is surprisingly messy, and too easy
to spec behaviors that can't always be implemented. Someone (not me!)
should volunteer to focus on this.

-Doug






More information about the cpp-threads mailing list