Need how to: Non Block-nested critical regions

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Need how to: Non Block-nested critical regions

Postby TriSebastian » Fri Dec 12, 2008 12:21 am

Hi!

I need to implements a logik like this C# routine:

Monitor.Enter(monitor);
...do something...
if (childCount > 0) {
Monitor.Enter(childMonitor);
Monitor.Exit(monitor);
... do something...
Monitor.Exit(childMonitor);
}
else {
Monitor.Exit(monitor);
}


I'm not sure whether this is the same in VASmalltalk:

|lock childlock|
lock := Semaphore forMutualExclusion.
childlock := Semaphore forMutualExclusion.

lock critical: [
.... do something...
self childCount > 0
ifTrue:[
childlock critical: [... do something...].
]
].


In Smalltalk/X there's a similar implementation of Monitor like in .Net but I didn't surely find on in VASmalltalk.

Any advice?

Thanks!
Sebastian
TriSebastian
 
Posts: 76
Joined: Sun Jul 20, 2008 9:40 pm
Location: Nanaimo, BC, Canada

Re: Need how to: Non Block-nested critical regions

Postby tc » Fri Dec 12, 2008 10:23 am

The two pieces of code look equivalent if the 'do something' in your code is creating other processes. If not then the code does not make sense because when you enter the first critical block, all other processes have to wait and the second critical block is not needed.

If the first critical block entered creates other processes that must wait then the second critical block makes more sense.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: Need how to: Non Block-nested critical regions

Postby TriSebastian » Fri Dec 12, 2008 11:52 am

Thanks tc,

yes they do!

I need to implement a server client session logging framework, having several loggers for on session and additional to that some loggers are shared between several sessions.....

But any way.
How could I implement a logic, allowing a parent logger to add/receive new data into/for it's buffers, after he has called his children to log the actual given data.

Just change the blocks like that?
self lock critical: [... do something ...].
self hasChildren
ifTrue:[ self childlock critical:[... let children do something...]].
TriSebastian
 
Posts: 76
Joined: Sun Jul 20, 2008 9:40 pm
Location: Nanaimo, BC, Canada

Re: Need how to: Non Block-nested critical regions

Postby marten » Sun Dec 14, 2008 12:55 am

TriSebastian wrote:Thanks tc,

yes they do!

I need to implement a server client session logging framework, having several loggers for on session and additional to that some loggers are shared between several sessions.....

But any way.
How could I implement a logic, allowing a parent logger to add/receive new data into/for it's buffers, after he has called his children to log the actual given data.

Just change the blocks like that?
self lock critical: [... do something ...].
self hasChildren
ifTrue:[ self childlock critical:[... let children do something...]].


Consider about using SstSharedQueues for data sharing between application logic and logger logic and each logger is an own process ...
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest