Skip to content

Locked the source when copying, moving, assigning and swapping lists and dispatchers - #86

Open
Haititi wants to merge 1 commit into
wqking:masterfrom
Haititi:fix/lock-source-on-copy
Open

Haititi wants to merge 1 commit into
wqking:masterfrom
Haititi:fix/lock-source-on-copy

Conversation

@Haititi

@Haititi Haititi commented Oct 6, 2026

Copy link
Copy Markdown

The copy/move constructors, assignment operators and swap of CallbackList, EventDispatcher, HeterCallbackList and HeterEventDispatcher read the other object without locking its mutex, so they raced with other threads that were adding or removing listeners on it, although the document says all public functions are thread-safe. Now the source is locked while it's copied or moved, and both objects are locked (in address order, to avoid dead lock) when assigning or swapping. EventQueue and HeterEventQueue inherit the fix.

Assigning to a dispatcher while another thread dispatches on it is still not safe (the dispatching thread holds a pointer to a callback list the assignment replaces); this is pre-existing and now documented.

Added DualLockGuard because std::lock requires try_lock, which SingleThreading::Mutex doesn't have. Added multi threading unit tests and updated documents.

…and dispatchers

The copy/move constructors, assignment operators and swap of CallbackList, EventDispatcher,
HeterCallbackList and HeterEventDispatcher read the other object without locking its mutex,
so they raced with other threads that were adding or removing listeners on it, although the
document says all public functions are thread-safe. Now the source is locked while it's
copied or moved, and both objects are locked (in address order, to avoid dead lock) when
assigning or swapping. EventQueue and HeterEventQueue inherit the fix.

Assigning to a dispatcher while another thread dispatches on it is still not safe (the
dispatching thread holds a pointer to a callback list the assignment replaces); this is
pre-existing and now documented.

Added DualLockGuard because std::lock requires try_lock, which SingleThreading::Mutex
doesn't have. Added multi threading unit tests and updated documents.
@Haititi
Haititi force-pushed the fix/lock-source-on-copy branch from 8318aff to 0fa3070 Compare October 6, 2026 14:02
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

Successfully merging this pull request may close these issues.

1 participant