Skip to content

Commit

Permalink
Fix synchronized statement docs
Browse files Browse the repository at this point in the history
Multiple arguments are not supported, causing a comma operator error
instead. See: https://issues.dlang.org/show_bug.cgi?id=16057
  • Loading branch information
ntrel authored and PetarKirov committed Dec 4, 2023
1 parent f119afa commit ff553fe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions multithreading/synchronization-sharing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff553fe

Please sign in to comment.