From d568c5db597c6b03e7ed7d65ce0a32af0194137d Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 4 Dec 2023 11:21:30 +0000 Subject: [PATCH] Fix synchronized statement docs Multiple arguments are not supported, causing a comma operator error instead. See: https://issues.dlang.org/show_bug.cgi?id=16057 --- multithreading/synchronization-sharing.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/multithreading/synchronization-sharing.md b/multithreading/synchronization-sharing.md index f99e76c..7aa2637 100644 --- a/multithreading/synchronization-sharing.md +++ b/multithreading/synchronization-sharing.md @@ -24,16 +24,18 @@ its own variable. `synchronized` blocks are used to tell the compiler to create a critical section that can only be entered -by one thread at a time. +by one thread at a time. With no arguments, a unique mutex +for that statement alone will be locked and unlocked. synchronized { importStuff(); } -Within `class` member functions these blocks might be -limited to different member objects *mutexes* -with `synchronized(member1, member2)` to reduce -contention. The D compiler inserts *critical +Synchronization can be limited to just a class object's +*mutex* by passing the object as an argument using +`synchronized (obj)` to reduce contention. + +The D compiler inserts *critical sections* automatically. A whole class can be marked as `synchronized` as well in which case the compiler will make sure that just one thread accesses a concrete