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 » Mutex locks vs copy constructors
Mutex locks vs copy constructors [message #18266] Fri, 19 September 2008 15:54 Go to next message
cas_ is currently offline  cas_
Messages: 20
Registered: July 2008
Location: Poland
Promising Member
Hi!

I believe that copy constructors of Mutex::Lock, RWMutex::ReadLock and RWMutex::WriteLock should be declared private. Currently, they are public and this fact can easily lead to errors if someone is not careful enough. Core/Mt.h should be changed as follows:

struct Mutex::Lock {
	Mutex& s;
	Lock(Mutex& s) : s(s) { s.Enter(); }
	~Lock()               { s.Leave(); }
private:
	Lock( const Lock& );
};

struct RWMutex::ReadLock {
	RWMutex& s;
	ReadLock(RWMutex& s) : s(s) { s.EnterRead(); }
	~ReadLock()                 { s.LeaveRead(); }
private:
	ReadLock( const ReadLock& );
};

struct RWMutex::WriteLock {
	RWMutex& s;
	WriteLock(RWMutex& s) : s(s) { s.EnterWrite(); }
	~WriteLock()                 { s.LeaveWrite(); }
private:
	WriteLock( const WriteLock& );
};
Re: Mutex locks vs copy constructors [message #18276 is a reply to message #18266] Fri, 19 September 2008 20:50 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, using NoCopy as base class..
Re: Mutex locks vs copy constructors [message #18278 is a reply to message #18276] Fri, 19 September 2008 21:22 Go to previous message
cas_ is currently offline  cas_
Messages: 20
Registered: July 2008
Location: Poland
Promising Member
Great! Smile
Previous Topic: non-blocking socket.Write("test string") crash on linux [BUG?]
Next Topic: Web package: is there file upload support?
Goto Forum:
  


Current Time: Fri Apr 19 18:15:35 CEST 2024

Total time taken to generate the page: 0.03790 seconds