Comments (10)
我想應該是要加才對? XD
from pttbbs.
Lines 430 to 455 in 86f1574
Like this.
from pttbbs.
恩... 感覺直接改一行的話效能會降低
from pttbbs.
若要更謹慎的話,應可加上 ISO C11 的 _Atomic
或是 ISO C++11 的 std::atomic
,使用 lock-free atomic 型別。
To take it more carefully, either _Atomic
from ISO C11 or std::atomic
from ISO C++11 could be added for using the lock-free atomic type.
因為 lock-free atomic 像 volatile
一般,也可防止編譯器最佳化掉變數的重要存取指令,僅使用 _Atomic
即可。
Since lock-free atomics, like volatile
, can also prevent the compiler from optimizing out the important reading and writing instructions of the variables, it should be fine to use _Atomic
along.
References:
- About C11
_Atomic
: https://en.cppreference.com/w/c/language/atomic - About C++11
std::atomic
: https://en.cppreference.com/w/cpp/atomic/atomic
from pttbbs.
SHM 是一整個 data structure ,沒辦法用 _Atomic
吧。
from pttbbs.
用在當作 synchronization lock 的變數上面。
It is meant for the lock variable which is taken as the synchronization lock.
from pttbbs.
那是完全另一回事了。SHM 現在就是沒有 lock
from pttbbs.
不過在 SHM_t
中,有用途類似於 lock 的 member,例如:
UTMPbusystate
:
Lines 533 to 537 in 86f1574
Bbusystate
:
Lines 562 to 566 in 86f1574
以及其它名字帶 busystate
的 members。
這些 members 就適合使用 _Atomic
。
from pttbbs.
Not jut SHM, I think we need to add volatile to all cache.c variables:
/* cache.c */
SHM_t *SHM;
boardheader_t *bcache;
userinfo_t *currutmp;
although, since we have never see issues so far, I'd assume the compiler is smart enough to figure hat shm, bcache, and currutmp are non-cacheable pointers.
from pttbbs.
Figuring out which global pointers point to non-cacheable contents is theoretically impossible without using link-time optimization (LTO). Enabling LTO requires the flag -flto
to be explicitly passed to the compiler and the linker of GCC or Clang. However, this flag has never been used for PttBBS according to pttbbs.mk
.
Not every code which accesses the data pointed by these pointers is compiled with the code which makes these pointers point into the shared memory. These codes are linked together instead of being compiled together, so the compiler is unable to figure out such usages at compile-time.
The reason why issues have not been observed should be because there have been efforts to reduce the frequency of writing into shared memory in the PttBBS codebase.
Writes into shared memory are more restricted and secured in PttBBS compared to the most of other MapleBBS-family BBSes, although the race condition issues due to the time-slicing scheduling of Linux and especially multi-processor environments (which cannot be solved by using volatile
) seem to have not been addressed.
Note: The shared-memory–"caching" issue is about caching into the register of the processor (which volatile
prevents) but not about caching into the memory cache. Because the memory cache of shared memory is also shared among processes and threads, the contents of shared memory are in fact "cacheable" in the memory-cache sense.
from pttbbs.
Related Issues (20)
- whence in PttLock should be SEEK_SET? (or PttLock after lseek should set offset as 0?) HOT 4
- 請問如何找回ID和密碼 HOT 5
- (Forwarded from PttBug)「登入次數」的累計盲點 HOT 2
- Some articles in the searching result for the word "初音" are missing in board C_Chat HOT 1
- [Feature Request] Support more than 8 characters password HOT 10
- 可用單一信箱多次認證 HOT 2
- AOTP verification seems to be broken HOT 1
- Use ngx.exit(444)
- Add SO_REUSEPORT support to logind HOT 1
- User ID rename does not update regemaildb
- Email input length hardcoded HOT 1
- [Bug] Ptt web search logic error HOT 2
- logind compile error HOT 2
- 使用 Mac 連上 term.ptt.cc,在發表文章/發送站內信時按下 ^ + X 沒有任何反應 HOT 4
- 看板下面的 bar 在特定情況下會消失
- [propose] Replace .PASSWDS with DB (mongodb) HOT 6
- BRD_WARNEL 的註解有錯
- Possible one more i++ in cmsys.strip_nonebig5? HOT 1
- [資訊] 如果你收不到認證信的話 HOT 3
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 pttbbs.