Feature: atomic (critical-section sugar) #4
Replies: 5 comments 3 replies
-
|
Well, I would love the feature for complex or larger types though or for operations on simple types that have no InterlockedXXX equivalent. |
Beta Was this translation helpful? Give feedback.
-
|
The compiler generates code with lock prefix for those (1,2,4,8 bytes on X86_64) If a result is necessary the compiler generates: That code is much, much better than a cs, so beware of that. |
Beta Was this translation helpful? Give feedback.
-
|
But I welcome the atomic keyword if it simply generates the same code as above for simple types 1-4 on 32 and 1-8 on 64. Note that reads are already always atomic for those. |
Beta Was this translation helpful? Give feedback.
-
|
Forget the barriers. Only useful in some cases and are not really threadsafe. |
Beta Was this translation helpful? Give feedback.
-
|
I had similar idea too. Would be nice to have something like: But I'm not sure this is a compiler scope, for me it's more a preprocessor job. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
atomicI have an idea I think is great - I came up with it myself, but then found out other languages have it too, of course... Everything that might be useful is already implemented somewhere: lock / synchronized / std::lock_guard / std::scoped_lock / lock & defer unlock...
FPC Unleashed version:
atomic(optional args) <expr>;Sugar for initCS + enterCS-try-finally-leaveCS-end + doneCS.
atomicexpands to:atomic: enter CS -> try -> EXPRESSION -> finally -> leave CSInstead of doing all the initialization and finalization, coming up with a name for the CS, remembering it, entering it, leaving it, and writing the try-finally - you simply call
atomic. IMHO brilliant.Naming
atomicorlockare on the table. Feedback welcome.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions