EventSet #1

Open
opened 2023-04-07 12:09:29 +01:00 by deavmi · 0 comments
Owner

What is this?

This is to add anew feature which provides a way for a Thread to wait() not only on a single event but a "set" of Event(s).

Reason for adding

Someone may want this and it could be handy if one doesn't want to have to spawn multiple threads to do this (alright solution) or (worse solution) wait(5) and loop, as that wakes a lot. We have used select() for implementing the wait() method so adding an "event set" feature shouldn't be hard at all.

Would help for tristanable, I guess this isn't feature-request-creep.

This would mean we can tell which events were awoken and compute the difference between that and the events in the original "set".

API

The API should allow one to do something like this:

Event e1 = new Event();
Event e2 = new Event();

// Ensure a pipe exists for this thread for event e1 and e2
e1.wait(0);
e2.wait(0);

// Create a set of events
EventSet set = new EventSet([e1, e2]);

// Wait
Event[] awokenEvents = set.wait();

// TODO: DO something with the `awokenEvents`

The set.wait() should use select to I/O wait/sleep the process, then when the kernel's IO request is fulfilled we check which fds were awoken, map these to the events that make up the EventSet; then read of all their bytes; then return these Event(s) in the form of [e1, e2, ...] (an Event[]).

## What is this? This is to add anew feature which provides a way for a `Thread` to `wait()` not only on a single event but a _"set"_ of `Event`(s). ### Reason for adding Someone may want this and it could be handy if one doesn't want to have to spawn multiple threads to do this (alright solution) or (worse solution) `wait(5)` and loop, as that wakes a lot. We have used `select()` for implementing the `wait()` method so adding an _"event set"_ feature shouldn't be hard at all. Would help for tristanable, I guess this isn't feature-request-creep. This would mean we can tell which events were awoken and compute the difference between that and the events in the original _"set"_. ### API The API should allow one to do something like this: ```d Event e1 = new Event(); Event e2 = new Event(); // Ensure a pipe exists for this thread for event e1 and e2 e1.wait(0); e2.wait(0); // Create a set of events EventSet set = new EventSet([e1, e2]); // Wait Event[] awokenEvents = set.wait(); // TODO: DO something with the `awokenEvents` ``` The `set.wait()` should use select to I/O wait/sleep the process, then when the kernel's IO request is fulfilled we check which fds were awoken, map these to the events that make up the `EventSet`; then read of all their bytes; then return these `Event`(s) in the form of `[e1, e2, ...]` (an `Event[]`).
deavmi added the
enhancement
label 2023-04-07 12:09:42 +01:00
deavmi self-assigned this 2023-04-07 12:09:45 +01:00
deavmi added reference master 2023-04-07 12:15:12 +01:00
deavmi added the due date 2023-04-12 2023-04-07 12:22:37 +01:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2023-04-12

Dependencies

No dependencies set.

Reference: deavmi/libsnooze#1
No description provided.