Utility class to manipulate threads.
1 // example 1: function 2 void threadFunc() 3 { 4 ... 5 } 6 7 auto thread = new Thread(&threadFunc); 8 thread.launch(); 9 10 // example 2: delegate 11 class Task 12 { 13 void run() 14 { 15 ... 16 } 17 } 18 19 auto task = new Task(); 20 auto thread = new Thread(&task.run); 21 thread.launch();
Threads provide a way to run multiple parts of the code in parallel. When you launch a new thread, the execution is split and both the new thread and the caller run in parallel.
To use a $(U Thread), you construct it directly with the function to execute as the entry point of the thread. $(U Thread) has multiple template constructors, which means that you can use several types of entry points:
$(PARA The thread ends when its function is terminated. If the owner $(U Thread) instance is destroyed before the thread is finished, the destructor will wait (see `wait()`).)