Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 375
Joined: 14 Nov 2002 0:01

Mutex

Post by Martin Meyer »

Hello Thomas,

please check this; it might be a mistake otherwise please explain: Running the code

Code: Select all

class facts     myMutex : mutex := mutex::create(false).   clauses     run() :-         %stdIO::write(toBoolean(myMutex:isSet())),         myMutex:release().
throws an exception because a mutex that has not been entered cannot be released. However, if the commented-out line is enabled, no exception occurs and “true” is output.

Apparently, isSet/0 changes the state of the mutex. Yet the name suggests that the predicate is merely intended to query the state.
Regards Martin
User avatar
Thomas Linder Puls
VIP Member
Posts: 1513
Joined: 28 Feb 2000 0:01

Re: Mutex

Post by Thomas Linder Puls »

Yes, you are right our implementation of isSet (which is used for many other things than mutex'es) doesn't work for a mutex, because it will actually acquire the mutex.

There is no way to test ownership of a mutex, so I think we will implement the predicate to raise an exception for mutexes.
Regards Thomas Linder Puls
PDC