Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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: Thu May 02 19:37:51 CEST 2024

Total time taken to generate the page: 0.04116 seconds