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 » PROPOSAL: Monitor mutex in objects
PROPOSAL: Monitor mutex in objects [message #27378] Thu, 15 July 2010 11:42 Go to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi guys,

in C# there exists a nice feature,
lock(objectinstance)
{
//method code on now protected object
}

one can protect another object of beeing somehow accessed / modified, while oneself is treating with it. the object itself doesnt know about that and does not need to take care on providing any synchonisation features inside.

would it be possible to make something like that in upp as well?
as far as i know, c# compiler helps here somehow..

meanwhile:

here is another maybe usefull construction, came in mind while i was dealing with Mt.h..

#define LOCKER UPP::Mutex __locker
#define LOCKED INTERLOCKED_(__locker)

class MyClass
{
	void Method()
	{
		LOCKED
		{
		//your per object locked code
		}
	}
};
private:
	LOCKER;
}

it's unlicke the pure INTERLOCKED, which would generate a StaticMutex in every method the LOCKED is used.

if it is sensefull...
Re: PROPOSAL: Monitor mutex in objects [message #27387 is a reply to message #27378] Thu, 15 July 2010 14:11 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
here comes package on how i thought of it...
short description:

first section uses 2 Threads, operating on same String, using INTERLOCKED, which doesnt work, because it creates internal static Mutex,

second secton uses a helper construction, LOCKED, which uses a LOCKER placed Mutex instance in class to protect things, this could be done explicitly by placing a Mutex in class, and using Mutex::Lock(instance) scoped helper as well.

third section uses a Single() Mutex map, to protect arbitrary objects from 'outside' as i understood it from C#

maybe its helpfull..
  • Attachment: SigMon.rar
    (Size: 1.93KB, Downloaded 278 times)

[Updated on: Thu, 15 July 2010 14:12]

Report message to a moderator

Re: PROPOSAL: Monitor mutex in objects [message #27443 is a reply to message #27378] Sun, 18 July 2010 09:05 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Thu, 15 July 2010 05:42

hi guys,

in C# there exists a nice feature,
lock(objectinstance)
{
//method code on now protected object
}

one can protect another object of beeing somehow accessed / modified, while oneself is treating with it. the object itself doesnt know about that and does not need to take care on providing any synchonisation features inside.

would it be possible to make something like that in upp as well?
as far as i know, c# compiler helps here somehow..

meanwhile:

here is another maybe usefull construction, came in mind while i was dealing with Mt.h..

#define LOCKER UPP::Mutex __locker
#define LOCKED INTERLOCKED_(__locker)

class MyClass
{
	void Method()
	{
		LOCKED
		{
		//your per object locked code
		}
	}
};
private:
	LOCKER;
}

it's unlicke the pure INTERLOCKED, which would generate a StaticMutex in every method the LOCKED is used.

if it is sensefull...


class MyClass {
    Mutex lock;
    void Method() {
       INTERLOCKED_(lock) {
           ...
       }
    }
};


or (usually I like that more)

class MyClass {
    Mutex lock;
    void Method() {
       Mutex::Lock __(lock);
       ...
    }
};


I do not think we really need more...
Re: PROPOSAL: Monitor mutex in objects [message #27444 is a reply to message #27387] Sun, 18 July 2010 09:08 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Thu, 15 July 2010 08:11


third section uses a Single() Mutex map, to protect arbitrary objects from 'outside' as i understood it from C#

maybe its helpfull..


Maybe you might just want to inherit Mutex for class where you need that?

Still, my limited experience with MT tells me that such constructs in U++/MT are rarely needed.
Re: PROPOSAL: Monitor mutex in objects [message #27470 is a reply to message #27444] Mon, 19 July 2010 14:17 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
your're right Smile KISS is better here. and your last example is less work typing... i might change the example though to be an INTERLOCKED ... Mutex::Lock example if not present..
Previous Topic: Stop Download
Next Topic: Problem when compiling multiple threads
Goto Forum:
  


Current Time: Fri Apr 19 23:59:16 CEST 2024

Total time taken to generate the page: 0.03797 seconds