Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronizing multiple threads #15

Open
diggit opened this issue Jul 9, 2020 · 1 comment
Open

Synchronizing multiple threads #15

diggit opened this issue Jul 9, 2020 · 1 comment

Comments

@diggit
Copy link
Contributor

diggit commented Jul 9, 2020

I have situation where I want to have multiple threads waiting for some event. Ar::Channel sounds like the proper way to let threads wait for event. Unfortunately event is consumed by first waiting thread. To deliver event to multiple threads, I've found this solution

while (channel.send(eventValue, 0) == kArSuccess);

Is there cleaner way?

@flit
Copy link
Owner

flit commented Jul 18, 2020

There needs to be a cleaner way! 😄 Some random thoughts here…

First, we could simply consider adding a broadcast API for channels.

One issue with using channels is that you are copying a value to each thread. It's only minor, but if you are only notifying a thread that some event occurred then it might be an unnecessary action (and it's a call to memcpy())—although you could say that the value sent via the channel is the event ID. We could consider a channel send (and receive?) variant that doesn't copy any data to address this.

Another thought is that channels are more or less intended to be point-to-point. So using them with multiple senders/receivers doesn't quite match their conceptual use—even though the current implementation uses a list for blocked senders/receivers and therefore supports any number of each. That's kind of an artifact of blocked threads being easily managed through lists. I was wondering if channels could be optimized (both performance and code size) if they were made solely point to point.

I've also thought about generic thread notifications, where the fundamental difference from channels is that the use cases include one-to-many.

Overall, I'm open to reworking the set of core kernel objects so each type has clearly defined roles. I've also thought about adding a set of "extra" objects, built from the core, such as streams, RW lock, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants