Subj : Re: reliability of setting thread priority To : comp.programming.threads From : gottlobfrege Date : Fri Feb 25 2005 04:41 am Alexander Terekhov wrote: > gottlobfrege@gmail.com wrote: > [...] > > In particular, similar to the problems of static local initializers > > and implementing pthread_once, etc., I want to initialize a critical > > section in a thread safe manner. > > http://groups.google.de/groups?selm=3FA61F96.223FDE85%40web.de > > > I would use another critical section > > to guard the first CS, but that 'begs the question' as they say. :-) I > > could use a global named mutex (CreateMutex() under Win32), but that > > seems a bit heavy - and if I was going to use a mutex to make a > > criticalsection, maybe I should just use a mutex where the CS was going > > in the first place. > > Named mutex doesn't live long. It is used to serialize event > creation/init (and initial lock state change). Once it is done, > CloseHandle() is called. So what's your problem (priorities > aside for a moment)? > > regards, > alexander. No real problem, but a Win32 Mutex is about 5x slower than a criticalsection, and about 15x slower than using atomic exchanges. (Rough numbers) I had a real life case where there was possibly going to be 100s of these objects used, so speed matters. On the other hand, a would consider using a mutex for the portable version, if anyone thought that the priority setting stuff was problematic - correctness beats speed (almost) every time... Tony .