Vocabulary/tcapdot

From J Wiki
Jump to navigation Jump to search

>> <<   Back to: Vocabulary

T. y Set Debug Thread Verb

Rank Infinity -- operates on x and y as a whole -- WHY IS THIS IMPORTANT?


Warning.png This primitive is new in J9.04


T. y sets the debug thread number to y. The master thread is always thread 0. On entry into debug suspension, the debug thread is set to the number of the thread that caused the suspension.

During debug suspension, sentences are executed in the debug thread. Commands that end suspension, giving a line number to resume at or a value to be used as the value of the debugged sentence, execute in the debug thread but the value they produce is applied in the thread that caused the suspension.

T. y takes effect when its result becomes the result of a sentence entered from the keyboard during debug suspension.


Related Primitives

Execute as Task (t.)

x T. y Threads and Tasks Verb

Rank Infinity -- operates on x and y as a whole -- WHY IS THIS IMPORTANT?


Warning.png This primitive is new in J9.04


x T. y performs a thread- and task-related function depending on the value of x:

x T. y functions
Description x Type/

Precision
of Result

Type/

Precision
of y

Action
Create thread 0 Integer atom thread parameters (for the nonce, must be an empty list) Create a thread if possible. Result is the sequential thread number, or _1 if the thread could not be created. The master thread is thread 0.
Even if your code does not create tasks, the system can take advantage of any threads you create to make primitives run faster.
Number of worker threads 1 Integer atom '' The total number of worker threads that have been created.
Thread statistics 2 #idle,#unfinished '' #idle is the number of threads not working on a user task or an internal task. #unfinished is the number of user tasks that have not completed.
Number of executing thread 3 Integer atom '' The number of the currently-executing thread. The master thread is thread 0.
Rattle a box to get status 4 Integer array, one for each atom in y A box or array of boxes
The threads continue to run between calculation of each atom of this result
Status Result atom
Pyx waiting to run _
Pyx running in thread n n
Pyx completed with error number n -n
Pyx completed with no error _1000
Not a pyx _1001

Note: non-negative status codes indicate tasks which are not done yet.

Create a pyx 5 The created pyx The maximum number of seconds to wait for the result, or 0 for no limit A pyx is created. It is very easy to lock up the system with pyxes. For example, the sentence
5 T. 0
entered from the keyboard will lock up.
Install a value into a pyx 6 i. 0 0 pyx,<value value becomes the value of pyx, waking up any tasks that were waiting for it. It is illegal to store a value or errorcode into a pyx more than once.
Install errorcode into a pyx 7 i. 0 0 pyx,<errorcode pyx becomes a pyx in error, with error code errorcode, waking up any tasks that were waiting for it. It is illegal to store a value or errorcode into a pyx more than once.
Mutexes 10 i. 0 0 shared Create a mutex. shared is 0 for an exclusive mutex, 1 for a shared mutex (also called a recursive mutex). The mutex is opaque; its type, shape, and value are meaningful only as an argument to a mutex function, and they may not be displayed or modified; but the mutex may safely be passed as an argument or put into a box, and it is not considered boxed for the purposes of ;, L., and similar.
11 errorcode mutex[;timeout] Take an exclusive lock on mutex, waiting up to timeout seconds (or forever if timeout is _ or omitted). errorcode is 0 if the lock was taken, 1 if the request timed out. A timeout value of 0 will always return immediately.

The behavior when a mutex-owner requests a lock on the mutex it owns depends on the type of mutex: a fast mutex will never get the lock, while a shared mutex will return immediately with the lock.

13 i. 0 0 mutex Release the lock on the mutex. For shared mutexes, the lock is released only after every execution of (11 T. mutex) has been matched by a (13 T. mutex).
Destroy thread 55 i. 0 0 '' Immediately decrement the count of worker threads, and destroy the most-recently-created thread after it has finished execution.

Shared mutexes

A shared mutex (sometimes called a recursive mutex) is one which can be locked multiple times on the same thread. It must be unlocked as many times as it has been locked before it will be available to other threads. If an exclusive mutex is locked more than once on the same thread, an error will be thrown.

Exclusive and shared mutexes have similar performance; you should choose whichever one does a better job of enforcing application invariants.


Details

User-created pyxes can be used as semaphores using the following protocol. Note that attempting to display a pyx will wait for its value to be assigned.

Originating task     Responding task
localpyx=.5 T. 30
function t. '' localpyx;local_stuff
   
    'remotepyx remote_stuff'=.y
Set up shared data for responding task to use     Get ready to receive
'remotepyx remote_stuff'=.>localpyx     6 T. remotepyx,<(localpyx =. 5 T. 30);<local_stuff
*** The responding task has control of the shared data ***
6 T. remotepyx,<(localpyx =. 5 T. 30);<local_stuff     'remotepyx remote_stuff'=.>localpyx
*** The originating task has control of the shared data ***
Control can be passed back and forth indefinitely



Related Primitives

Execute as Task (t.)