From 50776d945fdcd1252dc2ed04b80efb5c7708ffdb Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Wed, 18 May 2016 15:10:00 +0000 Subject: [PATCH] added Semaphore>>forMutualExclusion --- stix/kernel/Process.st | 11 ++++++++--- stix/kernel/test-010.st | 21 ++++++++++----------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/stix/kernel/Process.st b/stix/kernel/Process.st index 5bd34a5..9092dce 100644 --- a/stix/kernel/Process.st +++ b/stix/kernel/Process.st @@ -68,6 +68,14 @@ { #dcl count waiting_head waiting_tail heapIndex fireTimeSec fireTimeNsec. + #method(#class) forMutualExclusion + { + | sem | + sem := self new. + sem signal. + ^sem + } + #method initialize { self.count := 0. @@ -104,11 +112,8 @@ #method critical: aBlock { -## TODO: implement this -" self wait. ^aBlock ensure: [ self signal ] -" } ## ================================================================== diff --git a/stix/kernel/test-010.st b/stix/kernel/test-010.st index f79d1e1..03d69f1 100644 --- a/stix/kernel/test-010.st +++ b/stix/kernel/test-010.st @@ -48,26 +48,25 @@ #method(#class) main { - - ## THIS CRASHES VM. PLEASE CHECK. CRASHES WHEN REPETITION IS 1000 |t1 t2 s1 s2 s3| 'START OF MAIN' dump. s1 := Semaphore new. - s2 := Semaphore new. + s2 := Semaphore forMutualExclusion. t1 := [ - 100 timesRepeat: ['BLOCK #1' dump]. - ##s2 critical: [ - ## 10 timesRepeat: ['BLOCK #1' dump ] - ##] + ##1000 timesRepeat: ['BLOCK #1' dump]. + s2 critical: [ + 10000 timesRepeat: ['BLOCK #1' dump ]. + Exception signal: 'Raised Exception at process t1'. + ] ] newProcess. t2 := [ - 100 timesRepeat: ['BLOCK #2' dump]. - ##s2 critical: [ - ## 10 timesRepeat: ['BLOCK #2' dump. ] - ##]. + ##1000 timesRepeat: ['BLOCK #2' dump]. + s2 critical: [ + 10000 timesRepeat: ['BLOCK #2' dump. ] + ]. s1 signal. ] newProcess.