Status: FixedWaitingToBePharoed
Owner: stephane.ducasse CC: siguctua Labels: Type-Squeak New issue 3231 by stephane.ducasse: Semaphore changes http://code.google.com/p/pharo/issues/detail?id=3231 Needs a really careful review.... A new version of Kernel was added to project The Inbox: http://source.squeak.org/inbox/Kernel-ul.514.mcz ==================== Summary ==================== Name: Kernel-ul.514 Author: ul Time: 7 November 2010, 4:21:51.529 pm UUID: 5710b62a-4264-9947-acdc-11e0ce45021d Ancestors: Kernel-ul.513 A few changes to Semaphore: - save a block creation + activation + a possible context switch in #critical:ifCurtailed: - save a block creation + activation in #critical:ifError:, this changes the behavior when mutuallyExcludedBlock doesn't understand #ifError: - #critical:ifLocked: is guaranteed to not get locked. The earlier implementation sent #critical: which could cause a context change, so another process could enter the critical section before the original. - added a new method #passIfLocked: which is like #wait, but it doesn't wait for a signal if there's none, but evaluates the argument instead. =============== Diff against Kernel-ul.513 =============== Item was changed: ----- Method: Semaphore>>critical:ifCurtailed: (in category 'mutual exclusion') ----- critical: mutuallyExcludedBlock ifCurtailed: terminationBlock "Evaluate mutuallyExcludedBlock only if the receiver is not currently in the process of running the critical: message. If the receiver is, evaluate mutuallyExcludedBlock after the other critical: message is finished." + ^self critical: [ mutuallyExcludedBlock ifCurtailed: terminationBlock ] - ^self critical:[[mutuallyExcludedBlock value] ifCurtailed: terminationBlock] ! Item was changed: ----- Method: Semaphore>>critical:ifError: (in category 'mutual exclusion') ----- critical: mutuallyExcludedBlock ifError: errorBlock "Evaluate mutuallyExcludedBlock only if the receiver is not currently in the process of running the critical: message. If the receiver is, evaluate mutuallyExcludedBlock after the other critical: message is finished." | blockValue hasError errMsg errRcvr | hasError := false. blockValue := self critical:[ + mutuallyExcludedBlock ifError: [ :msg :rcvr | - [mutuallyExcludedBlock value] ifError:[:msg :rcvr| hasError := true. errMsg := msg. errRcvr := rcvr ]. ]. hasError ifTrue:[ ^errorBlock value: errMsg value: errRcvr]. ^blockValue! Item was changed: ----- Method: Semaphore>>critical:ifLocked: (in category 'mutual exclusion') ----- critical: mutuallyExcludedBlock ifLocked: alternativeBlock "Evaluate mutuallyExcludedBlock only if the receiver is not currently in the process of running the critical: message. If the receiver is, evaluate mutuallyExcludedBlock after the other critical: message is finished." - "Note: The following is tricky and depends on the fact that the VM will not switch between processes while executing byte codes (process switches happen only in real sends). The following test is written carefully so that it will result in bytecodes only." + + | caught | + caught := false. + ^[ + excessSignals = 0 + ifTrue: [ alternativeBlock value ] + ifFalse: [ + excessSignals := excessSignals - 1. + caught := true. + mutuallyExcludedBlock value ] ] + ensure: [ caught ifTrue: [ self signal ] ]! - excessSignals == 0 ifTrue:[ - "If we come here, then the semaphore was locked when the test executed. - Evaluate the alternative block and answer its result." - ^alternativeBlock value - ]. - ^self critical: mutuallyExcludedBlock! Item was added: + ----- Method: Semaphore>>passIfLocked: (in category 'communication') ----- + passIfLocked: aBlock + + excessSignals = 0 ifTrue: [ ^aBlock value ]. + excessSignals := excessSignals - 1! |
Comment #1 on issue 3231 by gazzaguru2: Semaphore changes http://code.google.com/p/pharo/issues/detail?id=3231 We can check perhaps (on old Squeak 3.9) with our rather process/semaphore intensive exchange software... |
Free forum by Nabble | Edit this page |