Board index » Visual Studio » cmutex ?
|
kjguillermo
|
|
kjguillermo
|
cmutex ?
Visual Studio60
Hello, I'd like to use this below code to protect some code in IE toolbar, but not sure if this is best choice, since IE is a window app: CSingleLock mlock(&m_Mutex); mlock.Lock() do some file writing here... mlock.Unlock() Do I risk something here? (m_Mutex is CMutex) regards - |
| Scott
Registered User |
Wed Oct 05 22:04:08 CDT 2005
Re:cmutex ?
buzz wrote:
QuoteHello, threads. It only works if both threads cooperate and use the same mutex. Used alone, the code above accomplishes nothing. It is half of a solution to some problems. -- Scott McPhillips [VC++ MVP] - |
| bobbi
Registered User |
Wed Oct 05 21:44:38 CDT 2005
Re:cmutex ?
That mutex is the same for alll instances of toolbar.
its declared as m_Mutex(FALSE, _T("xyz")) in contructor. I want to protect place where the file is being written ofcourse... "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>wrote in message Quotebuzz wrote: - |
| Scott
Registered User |
Thu Oct 06 08:26:01 CDT 2005
Re:cmutex ?
bobbi wrote:
QuoteThat mutex is the same for alll instances of toolbar. you are not dealing with one of those situations then the mutex accomplishes nothing. Multiple instances of a toolbar, all within an application's main thread, will never execute concurrently so they would never need mutex protection. If you don't understand, you could try to explain what you are trying to prevent, and why you think it might happen. So far, you have not mentioned a problem that needs a mutex solution. -- Scott McPhillips [VC++ MVP] - |
| bobbi
Registered User |
Thu Oct 06 10:09:47 CDT 2005
Re:cmutex ?
Of course I've mentioned, first: this is IE adds on, so you can have more
then one thread or more then one process, thats why I used mutex. That part I know, I didn't ask if I choose mutex right. I'm mot sure if I shouldn't use MsgWaitForMultipleObjects() instead of CSinleLock(). Second: My concern is that same file can be written by different IE threads or process. "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>wrote in message Quotebobbi wrote: - |
| Michael
Registered User |
Fri Oct 07 04:16:09 CDT 2005
Re:cmutex ?
bobbi wrote:
QuoteOf course I've mentioned, first: this is IE adds on, so you can have more needs to write to the file wait for all the others to have to write the file and make them write simultaneously? Give the mutex a more unique name. I wonder how many other amateur programs use xyz or qwerty as the mutex name. e.g. use "APPNAME_YOURNAME_DATE". Remember the MSDN warning: Security Note After creating the CMutex object, use GetLastError to ensure that the mutex did not already exist. If the mutex did exist unexpectedly, it may indicate a rogue process is squatting and may be intending to use the mutex maliciously. In this case, the recommended security-conscious procedure is to close the handle and continue as if there was a failure in creating the object. - |
