ThreadPool
Inherits: Resource
Resource that allows executing methods in a thread pool
Description
By default, the thread pool will create a thread for each detected core on the running machine. Each thread sleeps until a task is queued when method exec is called. When a task is queued, a thread will wake up and start working on the task until it is completed.
Properties
| Type | Name | Default |
|---|---|---|
| String | name | "ThreadPool" |
| int | size | |
| bool | running | false |
| Thread[] | threads | [] |
| Semaphore | semaphore | |
| Mutex | mutex | |
| ThreadPool.Task[] | queue | [] |
| CustomLogger | logger |
Methods
| Returns | Signature |
|---|---|
| void | start() |
| void | stop() |
| bool | is_running() |
| Variant | exec(method: Callable, name: String = "") |
Property Descriptions
name
String name = "ThreadPool"
Name of the thread pool
size
int size
Number of threads to create in the thread pool
running
bool running = false
Note
There is currently no description for this property. Please help us by contributing one!
threads
Thread[] threads = []
Note
There is currently no description for this property. Please help us by contributing one!
semaphore
Semaphore semaphore
Note
There is currently no description for this property. Please help us by contributing one!
mutex
Mutex mutex
Note
There is currently no description for this property. Please help us by contributing one!
queue
ThreadPool.Task[] queue = []
Note
There is currently no description for this property. Please help us by contributing one!
logger
CustomLogger logger
Note
There is currently no description for this property. Please help us by contributing one!
Method Descriptions
start()
void start()
Starts the threads for the thread pool
stop()
void stop()
Stops the thread pool
is_running()
bool is_running()
Returns whether or not the thread pool is running
exec()
Variant exec(method: Callable, name: String = "")
Calls the given method from the thread pool. Internally, this queues the given method and awaits it to be called during the process loop. You should await this method if your method returns something. E.g. codevar result = await thread_pool.exec(myfund.bind("myarg"))/code