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!
|