This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
assumeUnshared: convert shared lvalue to a non-shared one
- Loading branch information
1 parent
523ecda
commit 106d4ff
Showing
2 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
`core.atomic.assumeUnshared` has been added | ||
|
||
$(REF assumeUnshared, core,atomic) allows to convert a shared lvalue to a non-shared lvalue | ||
|
||
--- | ||
shared static int i; | ||
|
||
// i is never used outside of synchronized {} blocks... | ||
|
||
synchronized | ||
{ | ||
++i; // ERROR: cannot directly modify shared lvalue | ||
|
||
atomicOp!"+="(i, 1); // possible overhead | ||
|
||
// Directly modify i | ||
assumeUnshared(i) += 1; | ||
// or: | ||
++assumeUnshared(i); | ||
// or: | ||
i.assumeUnshared += 1; | ||
} | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters