Skip to content

redbean: concurrency improvements#1332

Merged
jart merged 5 commits intojart:masterfrom
mrdomino:redbean-concurrency
Dec 2, 2024
Merged

redbean: concurrency improvements#1332
jart merged 5 commits intojart:masterfrom
mrdomino:redbean-concurrency

Conversation

@mrdomino
Copy link
Copy Markdown
Collaborator

@mrdomino mrdomino commented Dec 2, 2024

In the course of playing with redbean I was confused about how the state
was behaving and then noticed that some stuff is maybe getting edited by
multiple processes. I tried to improve things by changing the definition
of the counter variables to be explicitly atomic. Claude assures me that
most modern Unixes support cross-process atomics, so I just went with it
on that front.

I also added some mutexes to the shared state to try to synchronize some
other things that might get written or read from workers but couldn't be
made atomic, mainly the rusage and time values. I could've probably been
less granular and just had a global shared-state lock, but I opted to be
fairly granular as a starting point.

This also reorders the resetting of the lastmeltdown timespec before the
SIGUSR2 signal is sent; hopefully this is okay.

@github-actions github-actions bot added the tool label Dec 2, 2024
@jart jart self-requested a review December 2, 2024 22:00
-1, 0)));
pthread_mutexattr_t attr;
unassert(!pthread_mutexattr_init(&attr));
unassert(!pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. The time for this has come, now that PTHREAD_PROCESS_SHARED is pretty much finally fully supported.

@jart jart merged commit b40140e into jart:master Dec 2, 2024
@mrdomino mrdomino deleted the redbean-concurrency branch December 3, 2024 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants