It is currently Wed Feb 08, 2012 11:50 pm

All times are UTC



Welcome
Welcome to RHAPSODY4YOU

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, respond to polls, upload and download content, and access many other special features. Registration is fast, simple, and absolutely free, so please, register to join our community today.





 Page 1 of 1 [ 12 posts ] 
Author Message
 Post subject: Protect class with mutex
PostPosted: Thu Jan 21, 2010 9:07 am 
User avatar

Joined: Mon Jan 11, 2010 9:17 am
Posts: 16
Location: Braunschweig
Hi,

I am new to Rhapsody and no native English speaker. So I beg your pardon..


what is the simplest way to protect the access to a class with a mutex?

I am trying to model a class "Container" that will be accessed by two or more other classes. These other classes will get and set data from the container. Each class should run in its own thread, cause it is not clear when the Container will be called.

Maik


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Thu Jan 21, 2010 9:53 am 

Joined: Wed May 07, 2008 3:50 pm
Posts: 148
Location: Horsham, W Sussex, England
I know you can protect operations within a class with the operation property CG:Operation:Concurrency:guarded. This uses OMProtected (a mutex).


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Thu Jan 21, 2010 10:11 am 
User avatar

Joined: Mon Jan 11, 2010 9:17 am
Posts: 16
Location: Braunschweig
Thanks a lot shanz!

I read about OMProtected and OMGuarded. But I didn't find out how to use this in an simple way.

I'll try your idea.


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Fri Jan 22, 2010 10:35 am 
User avatar

Joined: Thu Sep 13, 2007 7:34 pm
Posts: 397
Location: London
Firstly, the "Containers" are built into Rhapsody so I'm wondering why you are creating a Container class.

But just to add to what's already been said, you make an attribute (Attr) Guarded by setting the appropriate property. Then if you use the setAttr(newvalue) and getAttr() autogenerated operations (good practice) a mutex will be used. You can make as many attributes guarded as you want but only one mutex will be created for the object.

The event interface of a class, i.e. those triggers that are dealt with on the statechart, is not reentrant. All events are processed by the object's active context, i.e. owning thread. The default active context is the main thread but you can make any class active and therefore create an event queue at a 'lower' level.

Fully understanding the event driven framework and the container classes already built into Rhapsody may make your problem go away. Have you an opportunity to get any training?


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Mon Jan 25, 2010 9:14 am 
User avatar

Joined: Mon Jan 11, 2010 9:17 am
Posts: 16
Location: Braunschweig
Thanks a lot for the replies.

Farquad wrote:
Firstly, the "Containers" are built into Rhapsody so I'm wondering why you are creating a Container class.


I just have to receive and parse some UDP-signals. And therefore I have implemented some classes. One for each signal. They are very simple and just have to keep a lot of char and float values.

Farquad wrote:
... Have you an opportunity to get any training?


No, I haven't got the oppurtunity to get any training. I'll have to teach everything myself.

How exactly do I start the OX-framework? Do I have to initialize it?

If I used Rhapsody to implement a Class like:
class A
{
  ...
  int a; // guarded attribute
  int getA();
}


Do I just init the class in my main()? Is the getter already guarded by a mutex?

int main(int argc, char* argv[])
{
  A* a = new A();
  a->getA();
}


Sorry about the stupid questions. I just need a point to get started.

I'll go on ready reference manuals.


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Mon Jan 25, 2010 10:36 am 
User avatar

Joined: Thu Sep 13, 2007 7:34 pm
Posts: 397
Location: London
The best place to start is with an Essentials Training Course.

Rhapsody provides huge potential but understanding the basics underpins everything. I read modelling tool reviews from people who clearly have experimented without training and they end up giving low marks to Rhapsody but they have walked past a gold mine.

Why is Rhapsody not in common use? Lack of training.

Most things of worth require effort to unlock.

I found this on the web http://www.eecis.udel.edu/~bohacek/CTA- ... ediate.ppt.

It's an exert from an old version of the training but it answers your questions on creating objects in main.


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Mon Jan 25, 2010 11:36 am 
User avatar

Joined: Mon Jan 11, 2010 9:17 am
Posts: 16
Location: Braunschweig
Thanks Farquad!

I just got stuck. But I'll work through the presentation.


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Tue Jan 26, 2010 8:19 am 
User avatar

Joined: Mon Jan 11, 2010 9:17 am
Posts: 16
Location: Braunschweig
First I want to say "Thank You" again. The Tutorial is great. I am just working through all sections to get to know more basiscs.

Just one simple question:

Is creating an instance of a class through checking the box "This box is als an instance" in older versions of rhapsody the same as right clicking on the class at the object model diagram and saying "Make an object" in rhapsody 7.4?


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Tue Jan 26, 2010 7:25 pm 
User avatar

Joined: Thu Sep 13, 2007 7:34 pm
Posts: 397
Location: London
Making an object exist at a package level is unorthodox. However it's normal to create a composite class with objects (parts) inside and then instantiate it directly in the main by selecting it in the initialisation tab of a configuration.


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Fri Jan 29, 2010 10:09 am 
User avatar

Joined: Mon Jan 11, 2010 9:17 am
Posts: 16
Location: Braunschweig
Hello.

I made some progressss with my work. But: How Do I make a Singleton threadsafe?

I created a class Data according to the Singleton-Pattern (private constructor, static and guarded getInstance-Method, static var instance). Works fine so far.

But when I create some Test-classes each running in their own tread and accessing the Data-class it may happen, that there will be instanciated more than one data-object!

I guess its a Threading-problem. Is there any simple solution?


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Sat Jan 30, 2010 4:37 pm 
User avatar

Joined: Thu Sep 13, 2007 7:34 pm
Posts: 397
Location: London
"But when I create some Test-classes each running in their own tread and accessing the Data-class it may happen, that there will be instanciated more than one data-object!"

I don't understand the problem.

Is it possible to attach your model?


Offline
 Profile  
 
 Post subject: Re: Protect class with mutex
PostPosted: Tue Feb 02, 2010 10:14 am 
User avatar

Joined: Mon Jan 11, 2010 9:17 am
Posts: 16
Location: Braunschweig
Hi,

I am attaching a diagram to make the problem more clearly. I is not really a problem. It works.

The udp::Interface and the orcs::mw::Middleware use the two DataContainer-classes. The are "guarded" and implemented as a Singleton. But sometimes there are more instances than just one. I guess it is a Threading-problem.

Image


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

cron

suspicion-preferred