Title:

cancel - cancel the execution one or more threads.

Usage:

cancel(thread, wait=F)

Arguments:

thread:
a list or vector of threads or threadGroups. Recall that a string can be used to identify a thread when supplied to thread() or retrieved from the the threadthread handle/object.
wait:
if this is T, the call does not return until each thread has acknowledged its cancellation request. Otherwise, the call just sends the request to each thread and returns.

Side Effect:

The threads referenced in the argument thread are set to cancel mode. Each thread will terminate as soon as possible which is defined to be when it holds no locks. At the start and end of each evaluation of a complete expression, the thread checks to see if the cancel mode has been set and attempts to do so. The key point is that this is not an immediate cancel of a thread but merely a request which is processed in the future at the earliest possible instant.

NOTE:

This function behaves differently from suspend in that if no arguments are supplied, the thread that is cancelled is the calling thread, rather than all but the calling thread. Perhaps it should simply be an error.

Return Vaule:

A list of threads that were cancelled due directly to this call (rather than those that were are already in cancel mode). This is consistent with suspend.

See Also:

exit()
suspend()

Examples:

    grp = threadGroup("name")

    for(i in c(Quote({while(1) cat(n,connection=out)}), Quote(while(T){readLines(out,n=1)})) {
       thread(i, group=grp)
    }
    tA = thread(Quote(for(i in 1:1000) print(i)))
     
    cancel("name")  # cancel the collection of threads in the threadGroup.
                    # name is a synonym for threadGroup grp
    cancel(tA)      # cancel the individual thread

Key Words:

User Level Threads

Last modified: Thu Feb 6 17:35:17 1997