sx icon indicating copy to clipboard operation
sx copied to clipboard

threads: `sx_signal` seems to work differently on different platforms

Open mbullington opened this issue 1 year ago • 0 comments

Hello! I recently decided to integrate sx into a project to use it for threading / job allocation.

When converting from the largely Win32-esque threading API (the project is a fork of id Tech 4), it seemed like sx_signal worked differently than I'd expected, so I wanted to start a ticket with some of the issues I encountered & if my local fork might be a good fit. https://github.com/mbullington/sx/commit/d88166593430ca6048829e25cbdbc20373eda328

Largely I made it mirror Win32 Events more closely, in that it's a switch that gets "flipped" on and waits for listeners.

  • If there are already listeners we do a pthread_cond_broadcast & reset, otherwise we store the value for the next waiter.
  • Separate from these changes (but included in the Win32 API) I added a manual_reset, where the signal won't unflip upon a waiter, but instead needs to manually be reset with the sx_signal_reset_if_manual method.
  • Funny enough I actually removed the old Win32 API from this implementation, as it looks like there was compile-time branching that only ran it for Windows XP (< 6) and older. I figured by now we'd be onto Vista 😆 , and this is the only place in the codebase that had this branching.

If this isn't too opinionated—or you happen to agree—happy to open a PR. Thanks! 😄

mbullington avatar Sep 17 '22 22:09 mbullington