|
hoshi-lang dev
Yet another programming language
|
Hoshi-lang provides basic support for multi-threaded programming through the threading standard library module.
The Thread struct represents a single thread of execution. It is created with a callable object (a function or a lambda) that will be executed in the new thread.
constructor(callableObject: func () : none): Creates a new Thread with the given callable object.start() : lang.Result<unsigned, int>: Starts the execution of the thread. Returns a Result object containing the thread ID on success, or an error code on failure.join() : none: Waits for the thread to complete its execution.ping() : int: Checks if the thread is still running.The Mutex struct provides a mutual exclusion mechanism to protect shared data from being simultaneously accessed by multiple threads.
constructor(): Creates a new Mutex.lock() : none: Acquires the mutex lock. If the mutex is already locked by another thread, this call will block until it is released.unlock() : none: Releases the mutex lock.try_lock() : bool: Attempts to acquire the mutex lock without blocking. Returns true if the lock was acquired successfully, and false otherwise.The current_tid() function returns the ID of the currently executing thread.