任何人都知道,表达方式是原子建筑的价值。 审议以下职能。 能否保证这一行动的原样? (尽管需要额外的周期来计算2 << nr
?
static inline test_and_set_bit(volatile void *addr, int nr, int set) {
__sync_fetch_and_or(addr, set ? 2 << nr : 0);
}
感谢!
任何人都知道,表达方式是原子建筑的价值。 审议以下职能。 能否保证这一行动的原样? (尽管需要额外的周期来计算2 << nr
?
static inline test_and_set_bit(volatile void *addr, int nr, int set) {
__sync_fetch_and_or(addr, set ? 2 << nr : 0);
}
感谢!
The expressionset ? 2 << nr : 0
must be evaluation before the _sync_fetch_and_or(
operation isstart. 因此,进入<代码>addr的单向和(或)途径是原子——无问题。
Just to be clear - the read/modify/write actions to the memory pointed to by addr
will occur atomically - the evaluation of the value to be or ed in will not be atomic (but it doesn t need to be).
您的职能将相当于这一职能(很可能甚至会编纂到相同的法典):
static inline test_and_set_bit(volatile void *addr, int nr, int set) {
const int bit = set ? 2 << nr : 0;
__sync_fetch_and_or(addr, bit);
}
表达方式不会从原样上消失,而是因为它涉及所有与当地无关的变量。 <代码>_sync_fetch_and_or将原子执行。 你们也许想要改变你们的作用,看好这种作用,以便你们之后的人不会被混淆。
Following along from this question: how-do-i-check-if-gcc-is-performing-tail-recursion-optimization, I noticed that using gcc with -fPIC seems to destroy this optimization. I am creating a shared ...
I would like to know how to generate assembler code from a C program using Unix. I tried the gcc: gcc -c file.c I also used firstly cpp and then try as but I m getting errors. I m trying to build an ...
OK, I have old Metrowerks code for Mac and Windows where the previous developer used pre-compiled headers for every project that this code base builds. How does one get rid of Pre-compiled headers, ...
I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....
I ve recently set up a MinGW + MSYS environment on my laptop to check how things are with Netbeans C/C++ support. Everything seems to work fine, however, during my testing I have noticed a difference ...
I d like to compile my application for version 10.5 and forward. Ever since I upgraded to Snow Leopard and installed the latest XCode, gcc defaults to 10.6. I ve tried -isysroot /Developer/SDKs/...
We can get the type returned by function in gcc using the typeof operator as follows: typeof(container.begin()) i; Is it possible to do something similar for functions taking some arguments, but not ...
Is it possible to create binaries of other platform on Linux? Say I have a program that can be compiled using gcc to .o file but can we use it to output exe that can be run on windows ?