[Pharo-users] Determining if a Process is waiting on a Semaphore

Guillermo Polito guillermopolito at gmail.com
Tue Jan 5 08:32:37 EST 2016


Ben, did that help you?

> On 30 dic 2015, at 12:49 p.m., Guillermo Polito <guillermopolito at gmail.com> wrote:
> 
> A bit more on that:
> 
> Processor activeProcess suspendingList. => nil “An active process has nil as a list"
> Processor activeProcess isSuspended. => true??
> 
> 
> p := [  ] forkAt: 30.
> p suspendingList. => “the list where it is waiting ready to run"
> p isSuspended. => false?
> 
> s := Semaphore new.
> p := ([ s wait ] forkAt: 50). 
> p suspendingList. => “the semaphore where it is waiting to be unsuspended, since a semaphore is a list"
> p isSuspended. => false?
> 
> It is evident that a suspended process has the list where it is waiting, and the active process has nil.
> Then, I think the problem is that isSuspended is wrong.
> 
> isSuspended
> 	^myList isNil or: [ myList isEmpty ]
> 
> When it should be maybe
> 
> isSuspended
> 	^myList notNil
> 
> 
> Am I wrong?
> 
> Then, to actually answer your question, you can check if you are waiting in a semaphore or not, you can compare that the suspendingList is = to the semaphore. Of course we should also revise the API ^^.
> 
> s := Semaphore new.
> p := ([ s wait ] forkAt: 50). 
> p suspendingList == s
> 
> Guille
> 
> 
>> On 30 dic 2015, at 5:35 a.m., Ben Coman <btc at openinworld.com> wrote:
>> 
>> Looking at at the primitive comment in...
>> Semaphore>>wait
>>    "excessSignals>0
>>       ifTrue: [excessSignals := excessSignals-1]
>>       ifFalse: [self addLastLink: Processor activeProcess suspend]"
>> 
>> I expected/hoped the following...
>>  Transcript clear.
>>  s := Semaphore new.
>>  p := [ Transcript crShow: '1'. s wait. Transcript crShow: '2' ] forkAt: 50.
>>  Transcript crShow: p isSuspended.
>>  s signal.
>> 
>> would produce
>> 1
>> true
>> 2
>> 
>> but I get
>> 1
>> false
>> 2
>> 
>> How do I determine from another thread if a Process is waiting on a
>> Semaphore,  or even better, waiting on a particular semaphore?
>> 
>> cheers -ben
>> 
> 





More information about the Pharo-users mailing list