由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 问个线程同步的问题
相关主题
请问C++ exception后如何清理function stack上的内存资源?win 7 pro 正常情况多少进程/线程?
C++ InitializeCriticalSection问题大量读HBase的任务该加线程还是进程?
mutex一问线程共享变量问题,搞不懂。
编程题又一道Python 多线程或多进程如何搞
VC++线程问题waiting for N condition variables in linux
c++posix多线程问题请教Pthread一个牵涉两个线程同步,每轮先串行后并行的问题
关于多线程锁:锁代码还是锁资源?请教 boost locks
java里用synchronized包住block就可以保护多线程同步问题了,这就是c里面的mutex吧?is it possible to generate random tests for semphore/mutex/event APIs ... ?
相关话题的讨论汇总
话题: mutex话题: windows话题: 线程话题: 进程
进入Programming版参与讨论
1 (共1页)
B*****t
发帖数: 335
1
windows下如果我只有一个进程,还有必要用mutex同步这个进程下的多个线程么?是不
是CriticalSection完全够用了?
thanks!
X****r
发帖数: 3557
2
(Mostly) yes, if you're talking about these so named windows APIs (not
general concepts).

【在 B*****t 的大作中提到】
: windows下如果我只有一个进程,还有必要用mutex同步这个进程下的多个线程么?是不
: 是CriticalSection完全够用了?
: thanks!

O*******d
发帖数: 20343
3
在Windows下可以这样做。 这是Windows的东西。 如果你关注exception safety,
比较方便的是用MFC的CMutex,用CSingleLock来锁定CMutex,然后自动解锁。
CSingleLock不能用CriticalSection. 你可以自己写一个类,在constructor里加锁,
在destructor里解锁

【在 B*****t 的大作中提到】
: windows下如果我只有一个进程,还有必要用mutex同步这个进程下的多个线程么?是不
: 是CriticalSection完全够用了?
: thanks!

B*****t
发帖数: 335
4
thanks.
但是我的问题是如果我需要同步的是一个进程中的多个线程, 在什么情况下必须使用
mutex,而不能使用CriticalSection!

【在 O*******d 的大作中提到】
: 在Windows下可以这样做。 这是Windows的东西。 如果你关注exception safety,
: 比较方便的是用MFC的CMutex,用CSingleLock来锁定CMutex,然后自动解锁。
: CSingleLock不能用CriticalSection. 你可以自己写一个类,在constructor里加锁,
: 在destructor里解锁

s*******e
发帖数: 27
5
It should be the mostly same except that there might be some difference in
how they are implemented.
CS uses spin lock so in some case it is faster whereas mutex uses blocking
mechnism so it takes longer to wake up the sleeping thread.
Also mutex is a system object, i., directly provided by OS and used by
kernel as well. There is also something like recursive property so when you
are inside the mutex after entering it and somehow need to require the same
mutex ( not a usual case but could happen

【在 B*****t 的大作中提到】
: thanks.
: 但是我的问题是如果我需要同步的是一个进程中的多个线程, 在什么情况下必须使用
: mutex,而不能使用CriticalSection!

1 (共1页)
进入Programming版参与讨论
相关主题
is it possible to generate random tests for semphore/mutex/event APIs ... ?VC++线程问题
多线程的程序设计有什么好书推荐? (转载)c++posix多线程问题请教
java的同步问题请教关于多线程锁:锁代码还是锁资源?
问一下可能性,MingW生成的DLL和MSVC生成的DLL两个线程同步java里用synchronized包住block就可以保护多线程同步问题了,这就是c里面的mutex吧?
请问C++ exception后如何清理function stack上的内存资源?win 7 pro 正常情况多少进程/线程?
C++ InitializeCriticalSection问题大量读HBase的任务该加线程还是进程?
mutex一问线程共享变量问题,搞不懂。
编程题又一道Python 多线程或多进程如何搞
相关话题的讨论汇总
话题: mutex话题: windows话题: 线程话题: 进程