--- a/Semaphore.st Mon Feb 03 12:18:21 2003 +0100
+++ b/Semaphore.st Mon Feb 03 12:39:17 2003 +0100
@@ -257,6 +257,37 @@
proceedSema signalForAll.
Transcript showCR:'main thread: done.'.
[exEnd]
+
+ waitWithTimeout:0 can also be used to conditionally aquire the semaphore
+ i.e. only aquire it if its available.
+ |s|
+
+ s := Semaphore new.
+ [
+ (s waitWithTimeout:0) notNil ifTrue:[
+ Transcript showCR:'process1 got the sema'.
+ Delay waitForSeconds:1.
+ Transcript showCR:'process1 signals sema'.
+ s signal.
+ ] ifFalse:[
+ Transcript showCR:'process1 has NOT got the sema'.
+ ].
+ ] fork.
+ [
+ (s waitWithTimeout:0) notNil ifTrue:[
+ Transcript showCR:'process2 got the sema'.
+ Delay waitForSeconds:1.
+ Transcript showCR:'process2 signals sema'.
+ s signal.
+ ] ifFalse:[
+ Transcript showCR:'process2 has NOT got the sema'.
+ ]
+ ] fork.
+ s signal.
+ Delay waitForSeconds:0.5.
+ Transcript showCR:'master waits for sema'.
+ s wait.
+ Transcript showCR:'master got the sema'.
"
! !
@@ -804,5 +835,5 @@
!Semaphore class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Semaphore.st,v 1.67 2003-01-30 17:19:13 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Semaphore.st,v 1.68 2003-02-03 11:39:17 ca Exp $'
! !