Opened 10 years ago
Closed 10 years ago
#8449 closed Feature Requests (fixed)
Provide swap() and/or move for signals
Reported by: | Andrey Semashev | Owned by: | Frank Mori Hess |
---|---|---|---|
Milestone: | To Be Determined | Component: | signals2 |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Please, provide a member swap() function (and a free swap() overload) for signals. Moving support would also be helpful.
Swapping can be useful to solve deadlock problems in user's code. Consider the following example:
- We have an object a1 of class A, which contains a signal and a mutex for protecting A's internal state.
- We have a number of objects b1 - bN of types B1 - BN which subscribe for the signal in A.
- The signal in a1 is a one-time notification (i.e. it and the a1 object itself will be destroyed soon after the notification). When it is invoked, the mutex has to be locked to protect the signal from being modified.
- The b1 - bN objects may need to call back methods of a1 while being notified. These methods may need to lock the mutex in a1 but this would lead to a deadlock.
A typical solution for this problem is to move the signal to stack while holding the mutex, then release the mutex and invoke the signal. But this is not possible because signals do not allow swapping or moving.
Change History (2)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Adding swap and move is fine by me. I'll try to do this soonish. If you are impatient, and can brave all the preprocessor macros in signal_template.hpp, then sending a patch would also be fine. I believe implementing swap should be relatively trivial, since the signal classes are pimpls with only one data member: a shared_ptr to an implementation class.