Skip to content

Simplify shm_unix SharedMemoryRegistry - #7030

Open
niklasf wants to merge 1 commit into
official-stockfish:masterfrom
niklasf:shm-unix-simplify-registry
Open

Simplify shm_unix SharedMemoryRegistry#7030
niklasf wants to merge 1 commit into
official-stockfish:masterfrom
niklasf:shm-unix-simplify-registry

Conversation

@niklasf

@niklasf niklasf commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

The SharedMemoryRegistry now directly keeps a list of socket paths to unlink in the atexit handler.

Before, there were two minor issues:

  • Unsynchronized access to some SharedMemory members between open() and close(AtExit), and close(AtExit) nulling data_ptr_ and search threads using it, though of course only when we were about to exit anyway.
  • Moved from socket_path_ not nescessarily emptied and would then be unlinked, though I don't think any C++ implementation actually does that.

Also now just one atomic linked list away from a signal-safe cleanup_at_exit(), but one step further from a shared memory implementation that needs more general global cleanup work.

No functional change

The SharedMemoryRegistry now directly keeps a list of socket paths to
unlink in the atexit handler.

Before there were two minor issues:

- Unsynchronized access to some SharedMemory members between open() and
  close() called from the atexit handler, though of course only when we were
  about to exit anyway.
- Moved from socket_path_ not nescessarily emptied and would then be
  unlinked, though i don't think any C++ implementation actually does that.

Also now just one atomic linked list away from a signal-safe cleanup_at_exit(),
but one step further from a shared memory implementation that needs more
general global cleanup work.
@anematode

Copy link
Copy Markdown
Member

The atomic linked list would be really nice... but it's not clear how to do concurrent removal.

Sopel brought up the idea of just having a bounded static vector, which could work well, but maybe incompatible with our future libfish ambitions

@niklasf

niklasf commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Maybe easier if remove/add still takes a mutex, while trying to keep iteration without a mutex safe. Not sure.

@anematode

Copy link
Copy Markdown
Member

right, well one approach I had was to keep the mutex, and atomically exchange a pointer to the std::vector (with nullptr). Then the signal handler can try to acquire it atomically, and if it's nullptr, give up. Failure would only happen with receiving a signal in the middle of construction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants