added Semaphore>>forMutualExclusion
This commit is contained in:
parent
04ccebe9b4
commit
50776d945f
@ -68,6 +68,14 @@
|
|||||||
{
|
{
|
||||||
#dcl count waiting_head waiting_tail heapIndex fireTimeSec fireTimeNsec.
|
#dcl count waiting_head waiting_tail heapIndex fireTimeSec fireTimeNsec.
|
||||||
|
|
||||||
|
#method(#class) forMutualExclusion
|
||||||
|
{
|
||||||
|
| sem |
|
||||||
|
sem := self new.
|
||||||
|
sem signal.
|
||||||
|
^sem
|
||||||
|
}
|
||||||
|
|
||||||
#method initialize
|
#method initialize
|
||||||
{
|
{
|
||||||
self.count := 0.
|
self.count := 0.
|
||||||
@ -104,11 +112,8 @@
|
|||||||
|
|
||||||
#method critical: aBlock
|
#method critical: aBlock
|
||||||
{
|
{
|
||||||
## TODO: implement this
|
|
||||||
"
|
|
||||||
self wait.
|
self wait.
|
||||||
^aBlock ensure: [ self signal ]
|
^aBlock ensure: [ self signal ]
|
||||||
"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## ==================================================================
|
## ==================================================================
|
||||||
|
@ -48,26 +48,25 @@
|
|||||||
|
|
||||||
#method(#class) main
|
#method(#class) main
|
||||||
{
|
{
|
||||||
|
|
||||||
## THIS CRASHES VM. PLEASE CHECK. CRASHES WHEN REPETITION IS 1000
|
|
||||||
|t1 t2 s1 s2 s3|
|
|t1 t2 s1 s2 s3|
|
||||||
|
|
||||||
'START OF MAIN' dump.
|
'START OF MAIN' dump.
|
||||||
|
|
||||||
s1 := Semaphore new.
|
s1 := Semaphore new.
|
||||||
s2 := Semaphore new.
|
s2 := Semaphore forMutualExclusion.
|
||||||
|
|
||||||
t1 := [
|
t1 := [
|
||||||
100 timesRepeat: ['BLOCK #1' dump].
|
##1000 timesRepeat: ['BLOCK #1' dump].
|
||||||
##s2 critical: [
|
s2 critical: [
|
||||||
## 10 timesRepeat: ['BLOCK #1' dump ]
|
10000 timesRepeat: ['BLOCK #1' dump ].
|
||||||
##]
|
Exception signal: 'Raised Exception at process t1'.
|
||||||
|
]
|
||||||
] newProcess.
|
] newProcess.
|
||||||
t2 := [
|
t2 := [
|
||||||
100 timesRepeat: ['BLOCK #2' dump].
|
##1000 timesRepeat: ['BLOCK #2' dump].
|
||||||
##s2 critical: [
|
s2 critical: [
|
||||||
## 10 timesRepeat: ['BLOCK #2' dump. ]
|
10000 timesRepeat: ['BLOCK #2' dump. ]
|
||||||
##].
|
].
|
||||||
|
|
||||||
s1 signal.
|
s1 signal.
|
||||||
] newProcess.
|
] newProcess.
|
||||||
|
Loading…
Reference in New Issue
Block a user