aboutsummaryrefslogtreecommitdiff
path: root/core/sync
Commit message (Collapse)AuthorAgeFilesLines
* Remove `#no_copy`gingerBill2025-11-053-19/+19
|
* Further overhaul of package line comments.Jeroen van Rijn2025-10-092-8/+3
|
* Remove use of `.no_copy`gingerBill2025-07-301-1/+1
|
* Fix typogingerBill2025-07-301-1/+1
|
* Improve atomic logic for `sync.Wait_Group`gingerBill2025-07-301-12/+6
|
* Replace system:System.framework imports with system:SystemHarold Brenes2025-07-132-2/+2
| | | | This makes the linker work for both macOS and iOS targets
* core/sync/chan: (unbuffered) ack readsJack Mordaunt2025-06-131-3/+11
| | | | | | This fixes an issue where a call to close could intercept the dance between send and recv, causing send to report incorrectly that a value was not transmitted (when it actually was).
* core/sync/chan.send: return false if channel is closed while blockedJack Mordaunt2025-06-121-8/+15
| | | | | | | | | | | | This commit makes send behave the same as recv: that the call will return false if the channel is closed while a thread is waiting on the blocking operation. Prior logic would have send return true even if the channel was actually closed rather than read from. Docs adjusted to make this clear. Tests added to lock in this behaviour.
* core/sync/chan.try_send: avoid blocking if no reader is availableJack Mordaunt2025-06-121-7/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes the semantics of try_send to be consistently non-blocking. That is, if the buffered is full OR there are no readers it returns false. The previous behaviour was such that it would block in the latter case of no reader, and it would wait for a reader. That is problematic because it produces inconsistent behaviour between buffered and unbuffered channels which is astonishing and adds complexity to the caller. To illustrate the problem with the old behaviour, consider the try_select operation: if a send-channel happens to be unbuffered the try_select (which wants to never block) can now block, that unbuffered send channel is selected (at random) and there is no reader on the other side. Thus we have unpredictable blocking behaviour, which breaks the guarantee that try_select never blocks. If you want a blocking send you can just call "send" (the blocking variant). In addition, there is some reader/writer math done inside can_{send,recv} such that they only report true if there is sufficient reader/writer capacity. If there is contention we need to ensure that each reader is paired to exactly one writer. Consider try_send: if there is a single reader we can send. If there is a single reader and a single writer, then we cannot send, as that reader will be paired with the existing writer. Therefore can_send is only true if there are more readers than writers at the time of check. NOTE: The original tests don't need to use wait-looping with thread.yield() or heuristic sleep. Instead we can just use blocking channel operations rather than non-blocking operations.
* core/sync/chan.select_raw: call try_select_raw with deprecation warningJack Mordaunt2025-06-121-0/+5
| | | | | Eventually select_raw should be a blocking select operation, but for now we need to migrate people away.
* core/sync/chan.try_select_raw: fix doc comment typoJack Mordaunt2025-06-121-1/+1
| | | | Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
* core/sync/chan.try_select_raw: test hook for testing the toctouJack Mordaunt2025-06-121-0/+14
| | | | | | | This is necessary because we need to allow the test guarantee against a rare condition: where a third-party thread steals a value between the validity checks can_{send,recv} and the channel operation try_{send,recv}.
* core/sync/chan.try_select_raw: skip nil input messagesJack Mordaunt2025-06-121-1/+4
| | | | | This makes the proc easier and safer to call by letting the caller nil out messages to skip sends.
* core/sync/chan.try_select_raw: clarify loop control flowJack Mordaunt2025-06-121-3/+4
| | | | Use a label to clarify the continue statements.
* core/sync.try_select_raw: fix TOCTOUJack Mordaunt2025-06-121-32/+34
| | | | | | | | | | | | Fixes a TOCTOU where the channel could be used between the call to can_{recv,send} and {recv,send} causing an unexpected blocking operation. To do this we use the non-blocking try_{recv,send} and retry the check in a loop. This guarantees non-blocking select behaviour, at the cost of spinning if the input channels are highly contended. Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
* core/sync.select_raw: rename to try_select_rawJack Mordaunt2025-06-121-5/+7
| | | | | | | | This follows the convention where non-blocking operations are prefixed with "try" to indicate as much. Since select_raw in it's current form doesn't block, it should be try_select_raw, and allow select_raw to name a blocking implementation.
* core/sync.select_raw: return a useful indexJack Mordaunt2025-06-121-6/+22
| | | | | | | | | | | | | | | | | | This fixes a flaw in the original implementation: the returned index is actually useless to the caller. This is because the index returned refers to the internal "candidate" list. This list is dynamic, and may not have all of the input channels (if they weren't ready according to chan.can_{recv,send}). That means the index is not guaranteed to mean anything to the caller. The fix introduced here is to return the index into the input slice (recvs,sends) and an enum to specify which input slice that is. If no selection was made, then (-1, .None) is returned to communicate as much. Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
* Rewrite `Atomic_RW_Mutex`Feoramund2025-06-031-18/+42
| | | | | | | | | | | | | | This patch simplifies the implementation and fixes #5254. Previously, the mutex was set up as if there could be multiple writers, and there seemed to be some confusion as to which `Writer` bits to check, as not all were checked or set at the same time. This could also result in the mutex being left in a non-zero state even after unlocking all locks. All unneeded state has been removed and extra checks have been put in place.
* make once_do_without_data_contextless actually contextlessfusion322025-04-161-2/+2
|
* core:sync/chan: maintainance and package clarityRobin Bergewski2025-04-131-133/+134
| | | | | this deprecates all procedures around 'Raw_Queue' for it to become package private.
* fix indentRobin Bergewski2025-04-131-8/+8
|
* fix missing importsRobin Bergewski2025-04-132-0/+3
|
* changes due to reviewRobin Bergewski2025-04-131-1/+0
|
* core:sync/chan: add package documentationRobin Bergewski2025-04-132-0/+928
|
* [sync]: Fix typos in comments and remove my note.flysand72025-01-162-5/+2
|
* Haiku: fix futex bugavanspector2025-01-101-3/+3
|
* fix haikuavanspector2024-12-201-28/+26
|
* fix #4496 - allow unlock of unlocked mutex (making it consistent with ↵Laytan Laats2024-12-061-1/+1
| | | | windows behaviour)
* sync: fix no new valuesLaytan Laats2024-12-051-3/+3
|
* sync: fix require resultsLaytan Laats2024-12-051-3/+3
|
* sync: fix futexes on wasmLaytan Laats2024-12-051-15/+5
|
* Merge branch 'master' into file-tags-without-commentsKarl Zylinski2024-09-1710-126/+121
|\
| * fix wrong ulock timeout calculation, add version check for iosLaytan Laats2024-09-171-1/+4
| |
| * Pass microseconds instead of nanoseconds to __ulock_waitpkova2024-09-171-1/+1
| |
| * Fix code alignment in futex_darwin.odinPyry Kovanen2024-09-171-1/+1
| | | | | | Co-authored-by: Feoramund <161657516+Feoramund@users.noreply.github.com>
| * Fix core sync test deadlock on darwinpkova2024-09-171-2/+8
| |
| * Remove unneeded synchronizations in `Chan`Feoramund2024-09-151-43/+35
| | | | | | | | Everything was already guarded by `c.mutex`.
| * Fix commentsFeoramund2024-09-112-10/+10
| |
| * Add `cpu_relax` to `sync.auto_reset_event_signal`Feoramund2024-09-111-0/+1
| |
| * Fix deadlock in `Auto_Reset_Event`Feoramund2024-09-111-5/+4
| |
| * Fix data races in `sync.Recursive_Benaphore`Feoramund2024-09-111-15/+16
| |
| * Fix `recursive_benaphore_try_lock`Feoramund2024-09-101-4/+4
| | | | | | | | Previously, if the owner called this, it would fail.
| * Fix `chan.can_send` for unbuffered channelsFeoramund2024-09-101-1/+1
| | | | | | | | | | | | | | | | `w_waiting` is the signal that says a caller is waiting to be able to send something. It is incremented upon send and - in the case of an unbuffered channel - it can only hold one message. Therefore, check that `w_waiting` is zero instead.
| * Forbid `chan.try_send` on closed buffered channelsFeoramund2024-09-101-0/+4
| |
| * Fix deadlock on sending to full, buffered, closed `Chan`Feoramund2024-09-101-1/+6
| | | | | | | | | | This will also keep messages from being sent to closed, buffered channels in general.
| * Keep `chan.can_recv` from deadlockingFeoramund2024-09-101-1/+1
| |
| * Use `contextless` procs in `core:sync` insteadFeoramund2024-09-109-49/+33
| |
| * Fix atomic memory order for `sync.ticket_mutex_unlock`Feoramund2024-09-091-1/+1
| |
| * Fix data race in `atomic_sema_wait_with_timeout`Feoramund2024-09-091-1/+1
| |
| * Fix `sync.Benaphore`Feoramund2024-09-091-3/+3
| | | | | | | | | | The calls to `atomic_add*` return the value before adding, not after, so the previous code was causing the occasional data race.