Compare commits

...

2 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire b54983d7ab . 2023-06-26 18:52:07 +02:00
Tristan B. Velloza Kildaire 25610869b4 Unit tests
- Updated to make a call to `ensure(Thread)` and document why
- Removed the sleeps as the threads are now ensured
2023-06-26 16:48:32 +02:00
1 changed files with 17 additions and 2 deletions

View File

@ -492,6 +492,19 @@ version(unittest)
* Basic example of two threads, `thread1` and `thread2`,
* which will wait on the `event`. We will then, from the
* main thread, notify them all (causing them all to wake up)
*
* Note that when we construct the threads which will
* call `wait()`, we call `ensure(this)`. This is to
* make a mapping between that thread (the `this`)
* and a new pipe-pair which it can use then.
*
* Calling `wait()` would ensure it but we might have
* the main thread race down to call notify()
* BEFORE the pipe-pair is created and the thread
* would never receive the notification.
*
* It is standard practice to build your `wait()`ing
* thread object in this manner
*/
unittest
{
@ -505,6 +518,9 @@ unittest
{
super(&worker);
this.event = event;
// Ensure ourselves
this.event.ensure(this);
}
public void worker()
@ -521,10 +537,8 @@ unittest
TestThread thread2 = new TestThread(event);
thread2.start();
Thread.sleep(dur!("seconds")(10));
writeln("Main thread is going to notify two threads");
// TODO: Add assert to check
/* Wake up all sleeping on this event */
@ -586,6 +600,7 @@ unittest
{
super(&worker);
this.event = event;
this.event.ensure(this);
}
public void worker()