Multithreading
Operators and functions for working with threads (thread type) are described here.

Operator
Result
Description
thread = thread
Assignment operator.

The Lock function blocks access to the global resource (mutex). If it is already occupied by another thread, then the current thread is waiting for it to be released. The mutex must be freed using the Unlock function.

The resume function continues the work of the thread that was stopped by suspend function.

The SetThreadData function assigns a variable of type obj to the current thread. The value of the variable can be retrieved with the ThreadData function.

The sleep function pauses the current thread for at least the duration, in milliseconds.

The suspend function suspends the th thread. Use the resume function to continue the thread.

The terminate function terminates the thread. If the thread has already completed, the function does nothing.

The ThreadData function returns the object that was assigned to the current thread. A variable of type obj is assigned to the thread by the function SetThreadData.

The Unlock function releases access to a global resource (mutex).

The wait function waits for the th thread to finish. If the thread has already finished, the function does nothing.

The WaitAll function waits when the WaitGroup counter becomes zero.
run {
int count = 3
WaitGroup(count)
for i in 1..count {
go {
// ...
WaitDone()
}
}
WaitAll()
}

The WaitDone function decreases the counter WaitGroup by one.

The WaitGroup function creates a WaitGroup counter for the threads that should end with a calling the WaitDone function. count - the initial value of the counter.
Last modified 9mo ago
Copy link
On this page
Operators
Functions
Lock()
resume(thread th)
SetThreadData(obj o)
sleep(int duration)
suspend(thread th)
terminate(thread th)
ThreadData() obj
Unlock()
wait(thread th)
WaitAll()
WaitDone()
WaitGroup(int count)