Multithreading

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

Operators

Operator

Result

Description

thread = thread

Assignment operator.

Functions

Lock()

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.

resume(thread th)

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

sleep(int duration)

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

suspend(thread th)

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

terminate(thread th)

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

Unlock()

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

wait(thread th)

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

WaitAll()

The WaitAll function waits when the WaitGroup counter becomes zero.

run {
int count = 3
WaitGroup(count)
for i in 1..count {
go {
// ...
WaitDone()
}
}
WaitAll()
}

WaitDone()

The WaitDone function decreases the counter WaitGroup by one.

WaitGroup(int count)

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.