Redian新闻
>
Concurrency of assignment statement in C
avatar
Concurrency of assignment statement in C# Programming - 葵花宝典
s*n
1
请问各位大侠你们都在哪下电影啊?
现在迅雷被封了,给推荐几个网站呗。
好像看电影啊。
avatar
t*z
2
看凤凰卫视还有其他的直播节目的时候,经常自动退出来,不知道是怎么回事。多谢了!
avatar
s*y
3
【 以下文字转载自 FleaMarket 讨论区 】
发信人: superpanjy (Roger), 信区: FleaMarket
标 题: 【出售】自用的两条4GB 1066MHz DDR3 SDRAM - 2x4GB 可用于MBP imac
发信站: BBS 未名空间站 (Fri Jun 17 14:00:34 2011, 美东)
Kingston Apple 8GB Kit (2 X 4GB Modules) DDR3 1066MHz SODimm C7 iMac and
Macbook Pro Memory
因为apple 给我调换了机器 这两条内存用不上了
kingston
用在我2009年的MBP上没有什么问题
如有需要 请联系我
谢谢
avatar
s*r
4
This one is on sale, is it good?
avatar
M*n
5
I have the following statement in a function in one thread.
a = b;
Both a and b are 4-byte global variables. Now I have another thread that is
reading variable a too.
Is the above assignment atomic in x86_64?
If not, when the assignment resumes execution, will the stale b value (b
could have already been changed) or the updated b value be assigned to a?
avatar
t*b
7
凤凰的就是他们的官方的直播源,但非常不稳定。一旦断了就得重新进入。
凤凰的大多节目都有点播了,如果您喜欢的没有,请告知或者帮助我们添加。
avatar
I*8
8
哥,什马价格?
在内存和ssd之间犹豫
avatar
p*o
9
What do you mean by atomic? Do you know memory barrier?

is

【在 M**********n 的大作中提到】
: I have the following statement in a function in one thread.
: a = b;
: Both a and b are 4-byte global variables. Now I have another thread that is
: reading variable a too.
: Is the above assignment atomic in x86_64?
: If not, when the assignment resumes execution, will the stale b value (b
: could have already been changed) or the updated b value be assigned to a?

avatar
m*s
10
为啥divx web player 1.5下载不能啊
avatar
t*z
11
明白了!多谢!

【在 t**b 的大作中提到】
: 凤凰的就是他们的官方的直播源,但非常不稳定。一旦断了就得重新进入。
: 凤凰的大多节目都有点播了,如果您喜欢的没有,请告知或者帮助我们添加。

avatar
P*a
12
如果已经4G内存了,先上SSD

【在 I***8 的大作中提到】
: 哥,什马价格?
: 在内存和ssd之间犹豫

avatar
M*n
13
By non-atomic/atomic, I mean the assignment may be not completely finishged
before the context is switched to another thread.

【在 p***o 的大作中提到】
: What do you mean by atomic? Do you know memory barrier?
:
: is

avatar
f*j
14
我看很多直播都会不断loading,然后有时候就退出了, 会是因为我的网络速度不够吗?
avatar
d*e
15
make sure b is volatile socit is not cached in register

is

【在 M**********n 的大作中提到】
: I have the following statement in a function in one thread.
: a = b;
: Both a and b are 4-byte global variables. Now I have another thread that is
: reading variable a too.
: Is the above assignment atomic in x86_64?
: If not, when the assignment resumes execution, will the stale b value (b
: could have already been changed) or the updated b value be assigned to a?

avatar
f*o
16
同问,刚买了roku, 点播很好,直播几乎不能看。

我看很多直播都会不断loading,然后有时候就退出了, 会是因为我的网络速度不够吗?

【在 f*******j 的大作中提到】
: 我看很多直播都会不断loading,然后有时候就退出了, 会是因为我的网络速度不够吗?
avatar
w*g
17
问单个赋值操作是不是atomic没有意义。连续若干个读写操作才会有atomic或者memory
barrier的问题。

is

【在 M**********n 的大作中提到】
: I have the following statement in a function in one thread.
: a = b;
: Both a and b are 4-byte global variables. Now I have another thread that is
: reading variable a too.
: Is the above assignment atomic in x86_64?
: If not, when the assignment resumes execution, will the stale b value (b
: could have already been changed) or the updated b value be assigned to a?

avatar
M*n
18
Thanks

【在 d******e 的大作中提到】
: make sure b is volatile socit is not cached in register
:
: is

avatar
M*n
19
It matters to us since we need lokc-free concurrency.
We need to make sure that when the assignment occurs (no matter atomic or
non-atomic in that sense), the latest and updated value of b is used in the
assignment.

memory

【在 w***g 的大作中提到】
: 问单个赋值操作是不是atomic没有意义。连续若干个读写操作才会有atomic或者memory
: barrier的问题。
:
: is

avatar
p*o
20
You need to understand memory barrier in order to implement your own
lock-free code.

the

【在 M**********n 的大作中提到】
: It matters to us since we need lokc-free concurrency.
: We need to make sure that when the assignment occurs (no matter atomic or
: non-atomic in that sense), the latest and updated value of b is used in the
: assignment.
:
: memory

avatar
M*n
21
Thanks. I am not familiar with memory barrier. Just took a quick look at the
wiki page.
We don't care how compiler or CPU reordering the instructions.
All we care is that when that assignment is executed, the value assigned to
a is the value retrieved from b's actual memory address instead of some temp
register. Can this be guaranteed?

【在 p***o 的大作中提到】
: You need to understand memory barrier in order to implement your own
: lock-free code.
:
: the

avatar
M*n
22

Here is the illustration of a and b in two threads.
Thread 1 only writes to b and read a.
Thread 2 only writes to a and read b.
Thread 1 execution:
b = -1;
b = 0;
b = 1;
if(a != 0)
{
//do this
}
Thread 2 execution:
a = b;
// do that
Question is this:
Can the if condition be satisfied in thread 1 and 0 is assigned to a in
thread 2 (assuming a is initialized to -1 before both threads are started)?

【在 p***o 的大作中提到】
: You need to understand memory barrier in order to implement your own
: lock-free code.
:
: the

avatar
p*o
23
Sure, why not ...
1 For Thread 2, a=b can be compiled into two instructions.
2 Even if you can make a=b a single instruction, compiler/processor
can reorder the writes to b and reads from a in Thread 1.
Here is the book if you have time to read:
Is Parallel Programming Hard, And, If So, What Can You Do About It?
Otherwise try to find a library instead of writing your own code.

【在 M**********n 的大作中提到】
:
: Here is the illustration of a and b in two threads.
: Thread 1 only writes to b and read a.
: Thread 2 only writes to a and read b.
: Thread 1 execution:
: b = -1;
: b = 0;
: b = 1;
: if(a != 0)
: {

avatar
m*s
24
On 32bit machine, the assignment is atomic.
If both threads run on same cpu core, nothing to worry about.
However, if it's multi core, the read thread potentially run on another core
might still see stale "a" due to lack of memory barrier. You need to ask
for sync to achieve lock free.
Hope this helps.

By non-atomic/atomic, I mean the assignment may be not completely finishged
before the c........

【在 M**********n 的大作中提到】
: By non-atomic/atomic, I mean the assignment may be not completely finishged
: before the context is switched to another thread.

avatar
w*x
25
thread 1 execution:
try this:
b = -1;
smp_wb();
b = 0;
smp_wb();
b = 1;
smp_wb();
if(ACCESS_ONCE(a) != 0)
{
//do this
}
Thread 2 execution:
a = b;
smp_mb();
// do that
avatar
M*n
26
Thanks.
We have loads/assignments between these instructions that serve as memory
barrier already. If compiler reorder these instructions, it will break
single thread logic.

[发表自未名空间手机版 - m.mitbbs.com]

【在 w***x 的大作中提到】
: thread 1 execution:
: try this:
: b = -1;
: smp_wb();
: b = 0;
: smp_wb();
: b = 1;
: smp_wb();
: if(ACCESS_ONCE(a) != 0)
: {

avatar
w*x
27
mb/rb include both compiler memory barrier & cpu barriers.
avatar
r*s
28
All "lock free" concurrency are implemented using atomic instructions
such as compare and swap, which use memory barrier to ensure safety.
It is non-sensible that you use lock free concurrency without
understanding memory barrier. Even if you get this one right you would
make other serious mistakes somewhere else.
Usually compilers won't allocate registers across instructions that
carries memory barrier behavior. However sometimes compiler may get
confused because of programmer's mistake. For example, if your
variable has an alias, and that alias is assigned to a temp variable
you are doomed either way.

the

【在 M**********n 的大作中提到】
: It matters to us since we need lokc-free concurrency.
: We need to make sure that when the assignment occurs (no matter atomic or
: non-atomic in that sense), the latest and updated value of b is used in the
: assignment.
:
: memory

avatar
z*3
29
不一定
immutable一样可以满足lock free concurrency的需要
不过这贴我没看上下文,你们继续

【在 r***s 的大作中提到】
: All "lock free" concurrency are implemented using atomic instructions
: such as compare and swap, which use memory barrier to ensure safety.
: It is non-sensible that you use lock free concurrency without
: understanding memory barrier. Even if you get this one right you would
: make other serious mistakes somewhere else.
: Usually compilers won't allocate registers across instructions that
: carries memory barrier behavior. However sometimes compiler may get
: confused because of programmer's mistake. For example, if your
: variable has an alias, and that alias is assigned to a temp variable
: you are doomed either way.

avatar
r*s
30
I strongly suggest you give up your efforts and find someone to help you
No. Loads and assignments don't serve as memory barrier.
They can either be served
From cache or even registers. With multi core the chance
Of your code run as you expected is near 0
The topic of concurrent programming is a complex one and clearly
You don't even know the basics.

【在 M**********n 的大作中提到】
: Thanks.
: We have loads/assignments between these instructions that serve as memory
: barrier already. If compiler reorder these instructions, it will break
: single thread logic.
:
: [发表自未名空间手机版 - m.mitbbs.com]

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。