Semaphore use in signals

Open
#262 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp

Research direction

No file or test is named. Start by tracing the semaphore implementations used by interprocess_semaphore, especially the spin and POSIX paths, and how timed_wait interacts with SIGINT. Done means the project has a settled design for a non-throwing POSIX post and compile-time signal-safety information.

Written by the indexing model from the issue text.

Description

I am using interprocess' semaphore in conjunction with timed_wait, and I need to be able to handle SIGINT to terminate the waiting early. Looking into the implementation, I can see that I am getting the spin semaphore internally, which suggests to me that post()ing it from the signal handler is safe, since it is effectively just an atomic increment.

This would likely not hold in other types of internal implementations of the semaphore. For example, while POSIX implementation seems to be fine in the first line (it just uses sem_post), it can later throw an exception.

This leads me to two thoughts:

  1. Can we have a variant of the POSIX post() that would not throw an exception?
  2. Can we add compile-time introspection for signal safety of the chosen semaphore implementation? So that one can do something like static_assert(boost::interprocess::interprocess_semaphore::signal_safe_post).

I am happy to contribute such improvements if there's a consensus.

Dominant language
C++
Stars
185
Forks
131
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/interprocess

All issues in boostorg/interprocess

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.