Comments (8)
Hi!
-
Yes, this is compiler barrier. It's described in the paper at page 4:
I added the compiler barrier asm volatile("" ::: "memory)āthis is a GCC-specific compiler barrierāto make sure that the compiler won't move thr_p_[i].tail access and will access the memory location only onceāto load its value to tmp_t.
-
Basically I wrote the queue for x86 (including x86-64) architecture only. And the architecture in fact provides very strong memory ordering gurarntees. I particular 8.2.3.2 of Intel 64 and IA-32 Architectures Software Developerās Manual Volume 3: System Programming Guide specifies: "Neither Loads Nor Stores Are Reordered with Like Operations"
from blog.
@krizhanovsky,
to answer 1, If I remove the barrier, anything wrong there? Will any reorder happen? I can not understand the exactly meaning of the barrier position.
to answer 2, if i add barrier there, will it be portable to other weak memory model architecture such as ARM.
And is asm volatile("" ::: "memory)
portable to any platform with gcc? or i should use __sync_synchronize
instead when portable concerned.
from blog.
- It depends on compiler. It's better to compile the code and check assembly code wether the reordering takes place.
- I''m not familiar with ARM at all. However, I believe if you GCC intrinsics for barriers then the solution will be portable. The only reason why I didn't add the barriers for the queue to make it portable is performance: barriers are not for free and if you use a barrier when you don't need it, then you lose some performance.
- I'd use GCC intrisics for portability rather than inline assembly.
from blog.
@krizhanovsky,
still to answer 1, now that x86/64 provides very strong memory ordering gurarntees "Neither Loads Nor Stores Are Reordered with Like Operations", is the barrier necessary at the position?
from blog.
No, because we already have strict ordering of the operations.
from blog.
@krizhanovsky, thx for your answer š.
Inspired by your work, I have made a lock-free ringqueue which could deal with variable-length data. Could you give me any suggestion, any is greatly appreciated.
from blog.
You're wellcome ;) And thank you for the link - I'll have a look at the project.
from blog.
š, so I close the issue.
from blog.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.