U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ MT-multithreading and servers » sMutexLock implementation
sMutexLock implementation [message #15998] Thu, 22 May 2008 10:38 Go to previous message
hojtsy is currently offline  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?
 
Read Message
Read Message
Previous Topic: WaitForMultipleObjects() analog?
Next Topic: About U++ plugin/port of Webkit
Goto Forum:
  


Current Time: Sun Apr 26 05:49:42 GMT+2 2026

Total time taken to generate the page: 0.00439 seconds