Monitor with interfaces

Discussions related to Visual Prolog
Gildas Menier
VIP Member
Posts: 78
Joined: 8 Jun 2004 23:01

Monitor with interfaces

Unread post by Gildas Menier » 10 Apr 2011 16:25

I am playing with the nice monitor feature - thank you, no more mutex to track - and have a question :

Code: Select all

namespace gfc   interface hashtable{@Key,@Value}     open core   predicates         clear: ().     % @short clears the content     % @detail     % @end           put: (@Key, @Value) procedure (i,i).     % @short adds a value to the hashtable     % @detail     % @end             get: (@Key) -> @Value determ (i).     % @short tries to get a value (given the key)     % @fail no couple (key,value)     % @end           remove: (@Key)  procedure (i).     % @short removes a value     % @end           getSize:() -> integer procedure .     % @short returns the number of couples (key,value)     % @detail     % @end           getAll_nd: () ->  tuple{@Key, @Value} nondeterm ().     % @short gets all value (given the key)     % @end     end interface hashtable
I am trying to build a simple hashtable class (using tokyo cabinet http://fallabs.com/tokyocabinet/) and I would like to protect the access to the storing space.

I think using monitor should be enough, but of course, getAll_nd should'nt be protected by monitor (because it is nondeterm). Of course, in this case, getAll_nd should be protected by another mean (perhaps a mutex in this case, enclosing the part using getAll_nd)

But, in the general case, how can I protect a part of the interface and only a part of it ?

Regards

Gildas

User avatar
Thomas Linder Puls
VIP Member
Posts: 2447
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 10 Apr 2011 18:04

The language does not support mixing monitors with non-monitor entities.

You could consider returning a list with all elements instead of using nondeterministic iteration.
Regards Thomas Linder Puls
PDC

Gildas Menier
VIP Member
Posts: 78
Joined: 8 Jun 2004 23:01

Unread post by Gildas Menier » 10 Apr 2011 18:47

Returning a list is not an option since it can easily exceed the size of the memory.

Anyway, no problem to craft a class with dedicated mutex.

another question :

Monitor for class uses a mutex at class level (class fact), does monitor for interface uses a monitor at instance level ?

Thank you !

Regards

Gildas

User avatar
Thomas Linder Puls
VIP Member
Posts: 2447
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 10 Apr 2011 21:28

Yes, each monitor object has its own mutex.
Regards Thomas Linder Puls
PDC

Post Reply