-
Notifications
You must be signed in to change notification settings - Fork 373
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
Refactoring of waitset #341
Comments
There are some more topics to discuss for the waitset:
@ithier Would it be fine for you to extend the scope of this issue to a more general waitset issue? |
When I read this, I got the idea that the condition types could allow users to provide some callback via a
I might have gone in the complete wrong direction with this though, am I close ? |
Hmm, when the subscriber stores a callback reference it maybe makes no sense. Then we could do something like subscriber.executeCallback() and do not need an extra ID in the waitset. I was more thinking about callbacks and subscribers stored individually and that the searching/mapping could be saved. But make it makes more sense to have callback refs stored in the subscribers or subscriber ports. |
Signed-off-by: Christian Eltzschig <me@elchris.org>
… conditions are not depending on each other anymore Signed-off-by: Christian Eltzschig <me@elchris.org>
…cope Signed-off-by: Christian Eltzschig <me@elchris.org>
…mpty tests Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
While I was thinking about a more general to implement a waitset I encountered the following issue. Note that it may not apply here, but you may have to consider it even here. Assume we have a waitset W and have registered conditions, say C1 and C2 (which are all objects here). This is why conditions are supposed to be only manipulated under some kind of mutex protection to ensure proper operation. The bad part is of course that the window of time were those problems can happen is very small, so usually you will not observe this. This makes bugs related to it very hard to find. The consequences of this can be false positives and especially false negatives on wake-up. Now, there may be hope to not need a mutex under special circumstances, such as having "monotonic" conditions which may be set to true by other contexts, but can only be reset by the waitset itself. This may not be enough though, I have not fully thought about it. However, having non-monotonic conditions will surely cause these subtle problems. Just keep this in mind when you define the semantics of the waitset and implement it. |
Signed-off-by: Christian Eltzschig <me@elchris.org>
…prints a warning since you violate best practice Signed-off-by: Christian Eltzschig <me@elchris.org>
…was triggered Signed-off-by: Christian Eltzschig <me@elchris.org>
…condition was triggered Signed-off-by: Christian Eltzschig <me@elchris.org>
After further thought this is what I came up with. Note that this is only a very rough prototype but illustrates the use case as I see it https://github.com/MatthiasKillat/concurrency_primitives/blob/master/test_waitset_pub_sub.cpp A goal was to not need an explicit mutex, there may be an implicit one in a semaphore. One of my main gripes with the current waitset is unnecessary inheritance with those conditions (making it inflexible) and potential races (not sure!) in the condition checking. I believe it can be simplified but the use case needs to be better understood. I extracted the core functionality but designed it in a more generic way. My assumption is: we have one waiter (more is a misuse for now but can probably be extended), and our conditions are essentially monotonic (e.g. if there was data and nobody took it, then it is still there, it cannot dissapear). Now, my approach is to just say a waitset can register conditions The waitset may call wait in some thread T1, were it will block until it is notified. Assume the waitset was notifed. When it wakes up it has to check which internal conditions became true (by iterating, this seems unavoidable if one uses just one semaphore/condition variable internally for all conditions of the waitset). Here it is crucial that these conditions are monotonic, if they can become false concurrently (e.g. while iterating) we would need a mutex to protect anything that can change the value of the conditions(!). In pseudocode:
The interface is not perfect/final, but I think that is all there is to do, no inheritance needed. Currently removal of conditions is not possible and dynamic memory is used, both can be changed (the conditions must be a bit more restricted in this case, A subscriber can now simply hold a token (optionally) and interact with the waitset. This holds for any object that wants to work with a waitset. Remember: I only wanted to sketch the use scenario which I consider ideal, without losing generality if possible. :-) |
…cumented Signed-off-by: Christian Eltzschig <me@elchris.org>
…hing works only via waitset Signed-off-by: Christian Eltzschig <me@elchris.org>
…er to provide default arguments Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
… fixed an issue in the gateway example Signed-off-by: Christian Eltzschig <me@elchris.org>
…tset destructor Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
… renamed trigger left overs into event and adjusted docu Signed-off-by: Christian Eltzschig <me@elchris.org>
…lot of Us Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
iox-#341 implemented condition variable cleanup in waitset destructor
Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
…clipse-iceoryx#341-waitset-templatize-wait-for-better-performance
Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
…clipse-iceoryx#341-waitset-templatize-wait-for-better-performance
Signed-off-by: Christian Eltzschig <me@elchris.org>
Signed-off-by: Christian Eltzschig <me@elchris.org>
…for-better-performance Iox #341 improve waitset wait performance by returning TriggerInfo pointer
At the moment this is not a use case and I would pursue this when the need arises. |
Brief feature description
The current wait set API does not provide any mechanism for wait sets to identify the type of conditions that caused them to wake up.
The thread safety of the waitset is unclear. Do we support attach/detachCondition while another tread is doing the
wait()
?to be discussed, Would it make sense to have the conditions coupled to an (custom) ID and return a container of IDs instead of a container of conditions
Destroying a condition that is still attached to a waitset results in a error handler call. Shall we make this more robust and have a callable stored in the condition for things like detaching in d'tor?
The condition variable must be cleaned up in shared memory when the waitset is deleted (Ports are using the destroy() call from the BasePort and are cleaned up in the discovery loop, we need something similar for the condition variable), see also Clean up all shared memory resources when corresponding user objects go out of scope #369
Attach classes to a waitset which are copy- and/or movable.
Decrease the size of TriggerState to 8 bytes (if possible)
WaitSet triggerCapacity as template parameter
overload
attachTo
in subscriber and user trigger so that a callback can be attached without providing a trigger idrename
triggerCapacity
intocapacity
in waitsetrename
attachTo
in subscriber intoattachEvent
rename
acquireTrigger
intoacquireTriggerHandle
in waitset+1 for usertrigger, add this to WaitSet readme
Detailed information
Current wait set usage is as follows:
Here you can check each individual condition, but this can quickly become tedious if there are many attached conditions.
It would be beneficial to be able to identify the type of condition so that generic handling logic can be implemented.
The text was updated successfully, but these errors were encountered: