Repository navigation
[MrBot] Add robust_semaphore, a cross-process semaphore that survives holder crashes - #655
Open
Dan Cristoloveanu (dcristoloveanu) wants to merge 2 commits into
Open
Dan Cristoloveanu (dcristoloveanu) wants to merge 2 commits into
Dan Cristoloveanu (dcristoloveanu) wants to merge 2 commits into
Conversation
… whose units are released when the holding process dies
Member
Author
|
/azp run |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
robust_semaphore(win32), a named cross-process counting semaphore whose units are given back when the holding process dies.A Windows semaphore is not owned by anyone, so a unit taken by a process that crashes is lost until the semaphore is recreated.
robust_semaphoreuses N named mutexes<name>_<i>instead: a mutex is owned by a thread and is released (abandoned) by the OS when that thread or process dies.API
robust_semaphore_create(name, max_count, security_descriptor): opens the N mutexes (CreateMutexExA, optional SDDL) and starts one worker thread for the object.max_countis 1..63.robust_semaphore_acquire_async(h, timeout_ms, max_hold_ms, on_acquire_complete, context): one acquisition at a time per object. The callback always runs on the worker thread (never inline) with OK + unit index, TIMEOUT, CANCELLED or ERROR.robust_semaphore_cancel(h): stops a waiting acquisition.robust_semaphore_release(h): ends the hold (or stops a waiting acquisition).robust_semaphore_destroy(h): releases, stops and joins the worker. It can be called fromon_acquire_complete, in which case the worker frees the object.max_hold_msis counted from acquisition and includes the callback, so a unit is never held longer than that.Tests
max_countholders; separate names don't share units;robust_semaphore_tester) that is killed;win32/devdoc/robust_semaphore_requirements.md.