Title:

thread - creates an evaluator thread.

Usage:

thread( expression=NULL, name="", parent=NULL, start=T, group=NULL, priority=1, detach=F, access=parent(), onExit = NULL, input=NULL, output=NULL, error=NULL, attributes= threadAttributes(), toplevel=NULL, data=NULL, action=standardEval )

Arguments:

As you can see, there are very few required arguments for this function, but an overwhelming number of possible arguments to change the behavior of the thread at different points in its execution. See the documentation for User Level Threads for more details on how these arguments should be used appropriately.
expression
an expression or list of expressions to be evaluated in the new thread. These are appended to the task queue of this newly created thread in the same order as supplied here and processed sequentially.
action
the action used to process an element on the task queue. This should be a function that takes a single argument - the expression to be processed. The default value for this argument is standardEval.
parent
allows this new thread to appear as if created by another thread. This allows different inheritance of properties for this thread. These include the search path, the options vector and the input and output streams associated with the thread. This can be simulated via the command
      		      sendTask(thread(...),parent)
		    
start
on occassions, it is useful to create a thread but not have it start execution immediately. Passing F for this argument creates the thread in suspend mode and it can be started using the start() function. This is useful when we want to start two or more threads at approximately the same time or if we want to create several threads during an idle segment of the application to be used at a time in the future.
group
the newly created thread can be added to a threadGroup object on creation. This allows operations to be applied to multiple threads easily by operating on the threadGroup. This is a management facility. The addition of the new thread to the group is performed as a side effect and the group object is updated internally. So no re-assignment of the group to a local variable is necessary. These groups behave like databases and do not follow a functional language approach. These are effectively name tables or databases like the threadLock objects
priority
this specifies the attributes to be used when creating the thread. These are mainly used, at the moment, for controlling the C level thread associated with this user thread in the Pthreads implementation, but the attributes can be used by the manager. See threadAttributes and threadAttributes().
detach
this specifies the attributes to be used when creating the thread. These are mainly used, at the moment, for controlling the C level thread associated with this user thread in the Pthreads implementation, but the attributes can be used by the manager. See threadAttributes and threadAttributes().
access
this specifies the attributes to be used when creating the thread. These are mainly used, at the moment, for controlling the C level thread associated with this user thread in the Pthreads implementation, but the attributes can be used by the manager. See threadAttributes and threadAttributes().
attributes
this specifies the attributes to be used when creating the thread. Values passed individually override those supplied in this threadAttributes object. These are mainly used, at the moment, for controlling the C level thread associated with this user thread in the Pthreads implementation, but the attributes can be used by the manager. See threadAttributes and threadAttributes().
input:
the connection on which input is accepted by this thread. Usually this is inherited from the parent thread and is NULL, but it can be overridden here or in the attributes argument.
output:
the connection to which output is sent by this thread as a result of cat() and print() etc, commands. Usually this is inherited from the parent thread and is NULL, but it can be overridden here or in the attributes argument.
error:
the connection to which error and warning messages are sent by this thread. Usually this is inherited from the parent thread and is NULL, but it can be overridden here or in the attributes argument.
onExit
an expression or list of expressions to be evaluated when the thread exits, either normally via exit() or abnormally through another thread calling cancel() or some fatal error.
toplevel
this is the database to which all toplevel assignments should be comitted. The default is to make assign objects from evaluations of the tasks in ?. This can be supplied as an integer which is interpreted as an index into the search path, a character string identifying an element in the search path, or a database object itself.
data
data to be copied into the newly created thread's frame for easy access by the expressions being evaluated within this thread. This should be a list and the elements will be copied into objects in the threads database. Essentially we are unravelling the list into the first element of the search path for the newly created thread.
name
the name as a string to use for this thread in the evaluator manager and related references. When a thread handle is required, this name or the one in the thread handle can be used to identify the thread.

Side Effect:

A new thread is created and competes for process resources.

See Also:

threadGroup
threadAttributes

Examples:

      thread(Quote(fit = lm(x,y); return(fit))),
               data = list(x = x[[i]],y=y[[i]]),
               attributes = threadAttributes(priority=20)
            )

Key Words:

User Level Threads

Last modified: Mon Feb 10 15:26:10 1997