From J Wiki
Jump to navigation Jump to search

>> <<   Down to: Dyad   Back to: Vocabulary

[x] u t. n y Execute as task Conjunction

No rank -- the result is a verb with infinite rank

Warning.png This primitive is new in J9.04

   i. t. ''"0 i. 5
||0|0 1|0 1 2|0 1 2 3|

[x] u t. n y runs ([x] <@:u y) in an idle thread and returns its result, which is a pyx. A pyx is a special box. It looks like an atomic box and can be used like any other box. When the pyx is opened, the opening thread will block until the value is available. If the creation of the pyx ended in error, that error will be signaled when the pyx is opened.

The n argument to t. controls execution of the task. The format is

[[<]important parameters][,< keyword[;value]]...

The important parameters are: [threadpool#]

threadpool# indicates which threadpool the task should be assigned to. Threads are assigned to threadpools when they are created. By default, threadpool 0 is used.

One keyword has been defined.

The worker keyword controls whether the task should be executed in the originating thread if there is no waiting thread for it to run in.

   u t. 'worker'
   u t. (<'worker')
   u t. ('worker';1)

all indicate that the task should always be run in a worker thread if there is one. If the keyword is omitted, a value of 0 is used. If the value is omitted, a value of 1 is used

Note that local variables are not shared between threads. So any definitions used should be defined globally. (In the J904 beta-d, this includes the definition of u: In example t. '', the thread gets the name of u which in this case is example and if that name is not defined in that thread, you get a value error.)

Related Primitives

Threads and Tasks (T.)