Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix synchronized statement docs #378

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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