Subj : Re: reliability of setting thread priority To : comp.programming.threads From : gottlobfrege Date : Fri Feb 25 2005 06:00 am Alexander Terekhov wrote: > gottlobfrege@gmail.com wrote: > > [... DCSI and named mutexes ...] > > > I had a real life case where there was possibly going to be 100s of > > these objects used, so speed matters. > > Yeah, it would kinda matter if you have 100s of threads and 100s of > locals static all stuck in the initialization phase. Hardly "real > life case". > > regards, > alexander. No 100s of threads was not a concern, just hundreds of objects. In my original version, I was calling CreateMutex (with a unique name based on process ID and object address, etc) for *each* object - ie there was no contention between 2 different objects being initted, just if the same object was being initted. So I wanted to avoid that many CreateMutexes. I also considered _one_ mutex for all objects (per process), but then - the class has a static handle, and needs to be defined in *some* cpp. Not a real problem, but it was otherwise a h file only solution - easier to use/share. (I could use __declspec(selectany) but that would obviously need per-compiler porting.) And I have to carefully set the handle: if (!globalhandle) // or atomic read to ensure memory barrier { tmphandle = CreateMutex(somePerProcessName); oldhandle = exchange(&globalhandle, tmphandle); if (oldhandle) CloseHandle(oldhandle); // don't miscount } - I could not bother saving the handle and let CreateMutex find it for me by name, but then I would never get around to deleting it at program close. Windows will do it for me anyhow, but I'm not sure about other platforms. So even with a mutex I still need lots of 'exchange logic', so in that respect it doesn't seem better or worse than what I have. But it may very well be better in other respects. That's why I'm here asking. Part of the bigger picture is that I think I understand most of the pros and cons of the other methods, but was unsure of the messing with thread priorities. At the end of the day, I might go back to using a mutex, but was exploring other possibilities. Tony. .