由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 一个multithread的问题(是不是有人觉的很简单?)
相关主题
multi threading 还是 multi processing有专门介绍multithreading编程的书吗
来来,讨论一下multithread, multi-core, affinity急问一个学Multithreading编程的问题
multithread app的design要注意哪些问题?多线程计时不准std::thread尝鲜 问题
如果一个core,多线程还有必要吗?C++ timer class for multithreads?
请教c++ multithreading入门问题multithreaded vs multiprocess
真正的multi-threading是5个thread要5个cpu?那apache是真正的mc++11 std thread类 怎么样,大家用过么
请推荐几本Multi-threading的编程书籍C佳佳确实过时了
[合集] 请推荐几本Multi-threading的编程书籍a question regarding....
相关话题的讨论汇总
话题: possible话题: thread话题: create话题: f2话题: my
进入Programming版参与讨论
1 (共1页)
d*******n
发帖数: 369
1
1.
int i = 0 //i global variable
f1()
{
i++;
}
f2()
{
i = i + 2;
}
f3()
{
create thread(f1);
create thread(f2);
}
Possible values of i?
My answer is that 1, 2, or 3 is all possible
z****e
发帖数: 2024
2
why is 1 possible?
is "i++" an atom operation?
P********e
发帖数: 2610
3
你这条件不全吧

【在 d*******n 的大作中提到】
: 1.
: int i = 0 //i global variable
: f1()
: {
: i++;
: }
: f2()
: {
: i = i + 2;
: }

t****t
发帖数: 6806
4
c++03 didn't define "atomic" anyway. atomic is defined in c++0x, but
currently it's not implemented (actually partially) in gcc up to 4.5.
if you want atomic, you need to use 3rd party library.

【在 z****e 的大作中提到】
: why is 1 possible?
: is "i++" an atom operation?

z****e
发帖数: 2024
5
恩。

【在 t****t 的大作中提到】
: c++03 didn't define "atomic" anyway. atomic is defined in c++0x, but
: currently it's not implemented (actually partially) in gcc up to 4.5.
: if you want atomic, you need to use 3rd party library.

l******e
发帖数: 12192
6
没有看见高喊master,我很震惊

【在 z****e 的大作中提到】
: 恩。
z****e
发帖数: 2024
7
这点心理素质都没有?震惊帝。

【在 l******e 的大作中提到】
: 没有看见高喊master,我很震惊
l******e
发帖数: 12192
8
要有个适应过程

【在 z****e 的大作中提到】
: 这点心理素质都没有?震惊帝。
z****e
发帖数: 2024
9
等我过回头再多喊几声,把你的心理损失弥补回来。

【在 l******e 的大作中提到】
: 要有个适应过程
a*****i
发帖数: 268
10
0也有可能。都写在cache里面了。
d*******n
发帖数: 369
11
my explanation:
both threads could possibly read i before the "i" is written back by both
threads so they both could get its initial value 0. Then both thread could
write back last so the updated "i" could 1 or 2. Of course, its also
possible that one thread reads after the other writes back then it's 3

【在 d*******n 的大作中提到】
: 1.
: int i = 0 //i global variable
: f1()
: {
: i++;
: }
: f2()
: {
: i = i + 2;
: }

1 (共1页)
进入Programming版参与讨论
相关主题
a question regarding....请教c++ multithreading入门问题
面试问题一问 (转载)真正的multi-threading是5个thread要5个cpu?那apache是真正的m
重复利用threads的问题请推荐几本Multi-threading的编程书籍
Linux thread和NPTL thread什么关系? (转载)[合集] 请推荐几本Multi-threading的编程书籍
multi threading 还是 multi processing有专门介绍multithreading编程的书吗
来来,讨论一下multithread, multi-core, affinity急问一个学Multithreading编程的问题
multithread app的design要注意哪些问题?多线程计时不准std::thread尝鲜 问题
如果一个core,多线程还有必要吗?C++ timer class for multithreads?
相关话题的讨论汇总
话题: possible话题: thread话题: create话题: f2话题: my