Home » U++ Library support » U++ MT-multithreading and servers » sMutexLock implementation
sMutexLock implementation [message #15998] |
Thu, 22 May 2008 10:38 |
hojtsy
Messages: 241 Registered: January 2006 Location: Budapest, Hungary
|
Experienced Member |
|
|
In Mt.cpp there is
Mutex& sMutexLock()
{
static Mutex *section;
if(!section) {
static byte b[sizeof(Mutex)];
section = new(b) Mutex;
}
return *section;
}
How is this different from the simpler
Mutex& sMutexLock()
{
static Mutex m;
return m;
}
In both cases the Mutex constructor will be called when the function is first called. In both cases the function needs external protection from MT race conditions.
On a side note, this function is not on the interface (Mt.h), why not make it file static in Mt.cpp to avoid name clashes?
|
|
|
|
Goto Forum:
Current Time: Mon Jun 10 13:44:40 CEST 2024
Total time taken to generate the page: 0.01557 seconds
|