Hi, I'm a newbe concerning mutex objects. I tried implementing the Mutex object for aspell - win32 port. I found that I was failing to create the mutex when the lock was attempted in the constructor of a static object, with one exception.
For Win32 console applications, the constructors for static objects are called before main. That making a mutex at that time would fail does not seem particularly odd to me. Because it can fail at that time means that the code should just ignore the failure. However, what if making a mutex fails after main is called? What should be done? How can the program determine if the failure is legitimate? Does the unix version of aspell have the same situation? What should be done when an attempt to lock via a mutex fails? Are there other ways the code could be improved? About the exception. In my port I have this defined in typo_editdist.cpp. static TypoInfoCache<TypoEditDistanceInfo> typo_edit_dist_info_cache("keyboard"); For reasons unknown, its constructor can create a mutex. For what it's worth, this is my (debug) code. class Mutex { private: Mutex(const Mutex &); void operator=(const Mutex &); HANDLE hMutex; SECURITY_ATTRIBUTES sec; public: Mutex() { sec.nLength= sizeof(sec); sec.lpSecurityDescriptor = 0; sec.bInheritHandle = false; hMutex = 0; } ~Mutex() { if (hMutex) unlock();} void lock() { hMutex = CreateMutex(&sec,0,0); if (!hMutex) { DWORD err = GetLastError(); char buff[131]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,err,0,buff,sizeof(buff ),0); printf(buff); } } void unlock() { ReleaseMutex(hMutex); hMutex = 0;} }; Thanks for your help, Gary PS. I asked before how to test a locking via a mutex and received no replies. I ask again. Can anyone tell me how to go about verifying this feature? _______________________________________________ Aspell-devel mailing list [EMAIL PROTECTED] http://lists.gnu.org/mailman/listinfo/aspell-devel