Compare commits

...

13 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 0c89e59f5c
Merge pull request #6 from deavmi/feature/ensurable_parameter
Parameterized ensurability
2023-06-26 18:54:03 +02:00
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
Tristan B. Velloza Kildaire 8b7690f596 Event
- Fixed incorrect argument in `ensure(Thread)`'s call to `pipeExistenceEnsure(Thread)`
2023-06-24 15:07:40 +02:00
Tristan B. Velloza Kildaire ee5482400e Merge branch 'feature/interruptible' into feature/ensurable_parameter 2023-06-24 15:06:45 +02:00
Tristan B. Velloza Kildaire ccfbd3f515 Merge branch 'feature/interruptible' into feature/ensurable_parameter 2023-06-24 14:22:29 +02:00
Tristan B. Velloza Kildaire ea27388821 Merge branch 'feature/interruptible' into feature/ensurable_parameter 2023-06-23 22:02:04 +02:00
Tristan B. Velloza Kildaire 73a1dd60ee Merge branch 'feature/interruptible' into feature/ensurable_parameter 2023-06-23 21:57:02 +02:00
Tristan B. Velloza Kildaire 187a9b91de Event
- Removed now-completed TODO
2023-06-23 21:34:14 +02:00
Tristan B. Velloza Kildaire ab9198f67b Event
- Documented `ensure(Thread)`
2023-06-23 21:31:32 +02:00
Tristan B. Velloza Kildaire edc08391a1 Event
- `ensure()` now calls `ensure(Thread)`
- Implemented `ensure(Thread)` by moving the code from `ensure()` to it and parameterizing it with the parameter of `ensure(Thread)`
2023-06-23 18:45:36 +02:00
Tristan B. Velloza Kildaire 7911c25225 Event
- Clarified `ensure()`'s usage
2023-06-23 18:43:35 +02:00
Tristan B. Velloza Kildaire 73f333db04 Evenet
- Added TODO
2023-06-23 18:42:08 +02:00
1 changed files with 38 additions and 4 deletions

View File

@ -91,7 +91,7 @@ public class Event
*
* This can be useful if one wants to initialize several
* threads that should be able to all be notified and wake up
* on their first call to wait instead of having wait
* on their first call to wait instead of having `wait()`
* ensure the pipe is created on first call.
*
* Throws:
@ -103,8 +103,27 @@ public class Event
/* Get the thread object (TID) for the calling thread */
Thread callingThread = Thread.getThis();
/* Ensure the calling thread */
ensure(callingThread);
}
/**
* Ensures the existence of a pipe-pair for the provided
* thread. This is normally called before the thread in
* question would await the `Event` and before another
* thread, presumably the one calling `notify(Thread)`,
* would ever start doing so.
*
* Params:
* thread = the `Thread` to ensure a pipe entry for
* Throws:
* `FatalException` on creating the pipe-pair
* if needs be
*/
public final void ensure(Thread thread)
{
/* Checks if a pipe-pair exists, if not creates it */
pipeExistenceEnsure(callingThread);
pipeExistenceEnsure(thread);
}
/**
@ -473,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
{
@ -486,6 +518,9 @@ unittest
{
super(&worker);
this.event = event;
// Ensure ourselves
this.event.ensure(this);
}
public void worker()
@ -502,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 */
@ -567,6 +600,7 @@ unittest
{
super(&worker);
this.event = event;
this.event.ensure(this);
}
public void worker()