You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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.
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
Is there cleaner way?
The text was updated successfully, but these errors were encountered: