Boost intrusive list volatile hook
I intend to use the boost intrusive list to implement an observer pattern. - The list will cross interrupt boundaries; meaning one interrupt will produce the notifications and the other interrupt will observer the notifications. - The observer, in response to a notification, might detach itself from the list using the the hook's unlink() function. - I think that I will need the hook to be declared volatile in order to accommodate this. I have a minimal code sample here: https://github.com/natersoz/patterns/blob/master/observer/intrusive_list_mem... My list hook member declaration: using list_hook_type = boost::intrusive::list_member_hook< boost::intrusive::link_modeboost::intrusive::auto_unlink >; list_hook_type hook; My list declaration: using list_type = boost::intrusive::list< Observer<NotificationType>, boost::intrusive::constant_time_size<false>, boost::intrusive::member_hook< Observer<NotificationType>, typename Observer<NotificationType>::list_hook_type, &Observer<NotificationType>::hook> >; If I a the volatile keyword to the list hood type, I cannot figure out how to get the list_type declaration to fit into the list template list. Is it possible? Thank you. -- Nat Ersoz 425-417-5182 (cell)
Interrupts are like threads, except worse because you have also reentrancy issues (e.g., can IRQ A happen while the handler for IRQ A is still running, possibly outside of IRQ context). Volatile is not sufficient for several reasons, not the least because insertion/removal into a linked list is not an atomic operation. As I see it you have two choices:
1. Introduce fine-grained locking of list nodes by customizing boost.intrusive (you have to be careful because it’s easy to end up in a deadlock due to reentrancy issues – unless you have some constraints, like IRQ levels, that can prevent this.)
2. Use a lock-free list
You should read about how operating systems (Windows, Linux) tackle these issues.
From: Boost-users
I am fully aware that volatile is not sufficient when dealing with
interrupts and this specific problem.
That is not the question. The question is this:
*Can I qualify the list hook with volatile and still use the boost
intrusive list?*
I realize that I can modify or write my own intrusive list.
I would prefer to keep in step with boost if possible.
On Sun, Nov 25, 2018 at 10:56 PM Stian Zeljko Vrba
Interrupts are like threads, except worse because you have also reentrancy issues (e.g., can IRQ A happen while the handler for IRQ A is still running, possibly outside of IRQ context). Volatile is not sufficient for several reasons, not the least because insertion/removal into a linked list is not an atomic operation. As I see it you have two choices:
1. Introduce fine-grained locking of list nodes by customizing boost.intrusive (you have to be careful because it’s easy to end up in a deadlock due to reentrancy issues – unless you have some constraints, like IRQ levels, that can prevent this.) 2. Use a lock-free list
You should read about how operating systems (Windows, Linux) tackle these issues.
*From:* Boost-users
*On Behalf Of *nat ersoz via Boost-users *Sent:* Sunday, November 25, 2018 18:38 *To:* boost-users@lists.boost.org *Cc:* nat ersoz *Subject:* [Boost-users] Boost intrusive list volatile hook I intend to use the boost intrusive list to implement an observer pattern.
- The list will cross interrupt boundaries; meaning one interrupt will produce the notifications and the other interrupt will observer the notifications.
- The observer, in response to a notification, might detach itself from the list using the the hook's unlink() function.
- I think that I will need the hook to be declared volatile in order to accommodate this.
I have a minimal code sample here: https://github.com/natersoz/patterns/blob/master/observer/intrusive_list_mem...
My list hook member declaration:
using list_hook_type = boost::intrusive::list_member_hook<
boost::intrusive::link_modeboost::intrusive::auto_unlink
>;
list_hook_type hook;
My list declaration:
using list_type =
boost::intrusive::*list*<
Observer<NotificationType>,
boost::intrusive::constant_time_size<false>,
boost::intrusive::member_hook<
Observer<NotificationType>,
typename Observer<NotificationType>::list_hook_type,
&Observer<NotificationType>::hook>
>;
If I a the volatile keyword to the list hood type, I cannot figure out how to get the list_type declaration to fit into the list template list.
Is it possible?
Thank you.
--
Nat Ersoz 425-417-5182 (cell)
-- Nat Ersoz 425-417-5182 (cell)
On 26/11/2018 20:12, nat ersoz via Boost-users wrote:
I am fully aware that volatile is not sufficient when dealing with interrupts and this specific problem. That is not the question. The question is this: *Can I qualify the list hook with volatile and still use the boost intrusive list?*
Hi, Intrusive was not designed for that use case, so I'm afraid you are out of luck. Best, Ion
participants (3)
-
Ion Gaztañaga
-
nat ersoz
-
Stian Zeljko Vrba