Page 1 of 1

Monitor with interfaces

Posted: 10 Apr 2011 16:25
by Gildas Menier
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 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 ?



Posted: 10 Apr 2011 18:04
by Thomas Linder Puls
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.

Posted: 10 Apr 2011 18:47
by Gildas Menier
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 !



Posted: 10 Apr 2011 21:28
by Thomas Linder Puls
Yes, each monitor object has its own mutex.