all problems documented
This commit is contained in:
parent
37568c556c
commit
0f969e4355
@ -32,7 +32,7 @@ func main() {
|
||||
|
||||
log.Printf("*** Start\n")
|
||||
|
||||
var variant = "dekker"
|
||||
var variant = "a"
|
||||
if len(os.Args[1:]) > 0 { // do we have arguments?
|
||||
variant = os.Args[1]
|
||||
}
|
||||
|
@ -25,11 +25,18 @@ var turn = 1
|
||||
func Start() {
|
||||
go process1()
|
||||
go process2()
|
||||
/**
|
||||
|
||||
|
||||
Prozesse wechseln sich immer nur ab.
|
||||
Ablauf ist 1,2,1,2,1,2,1,2,1,2
|
||||
*/
|
||||
}
|
||||
|
||||
// process1 simulates the behaviour of the first process
|
||||
func process1() {
|
||||
L1:
|
||||
//wait till turn = 2 (program can run)
|
||||
if turn == 2 {
|
||||
//log.Printf("Process 1 waiting\n")
|
||||
goto L1
|
||||
@ -40,6 +47,7 @@ L1:
|
||||
controller.LeaveCriticalSection(1)
|
||||
|
||||
turn = 2
|
||||
//Process 2 can run now (and will in some cases)
|
||||
|
||||
controller.OutsideCriticalSection(1, 100)
|
||||
|
||||
@ -64,6 +72,7 @@ L2:
|
||||
controller.LeaveCriticalSection(2)
|
||||
|
||||
turn = 1
|
||||
//Process can run now (and will in some cases)
|
||||
|
||||
controller.OutsideCriticalSection(2, 100)
|
||||
|
||||
|
@ -16,6 +16,7 @@ package ewd123b
|
||||
import (
|
||||
"../controller"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
// global synchronization variables
|
||||
@ -25,14 +26,21 @@ var c1, c2 = 1, 1
|
||||
func Start() {
|
||||
go process1()
|
||||
go process2()
|
||||
/**
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
// process1 simulates the behaviour of the first process
|
||||
func process1() {
|
||||
L1:
|
||||
//wait till c2 = 0 (other process no longer inside critical section)
|
||||
if c2 == 0 {
|
||||
goto L1
|
||||
}
|
||||
//if the other process inspects c1 at this moment both will enter the critical section
|
||||
//we can force this behaviour if we wait for a moment
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
c1 = 0
|
||||
|
||||
|
@ -15,7 +15,7 @@ package ewd123c
|
||||
|
||||
import (
|
||||
"../controller"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
// global synchronization variables
|
||||
@ -32,6 +32,9 @@ func process1() {
|
||||
A1:
|
||||
c1 = 0
|
||||
L1:
|
||||
//if process 2 inspects c1 at this moment, both processes will wait for each other to set cX.
|
||||
//we can force this behavior if we wait for a moment
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if c2 == 0 {
|
||||
goto L1
|
||||
}
|
||||
@ -43,10 +46,12 @@ L1:
|
||||
c1 = 1
|
||||
controller.OutsideCriticalSection(1, 100)
|
||||
|
||||
if controller.ProcessCrashed(0.1) {
|
||||
log.Println("Process 1 crashed")
|
||||
return
|
||||
}
|
||||
/*
|
||||
if controller.ProcessCrashed(0.1) {
|
||||
log.Println("Process 1 crashed")
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
goto A1
|
||||
|
||||
@ -68,10 +73,12 @@ L2:
|
||||
c2 = 1
|
||||
controller.OutsideCriticalSection(2, 100)
|
||||
|
||||
if controller.ProcessCrashed(0.1) {
|
||||
log.Println("Process 2 crashed")
|
||||
return
|
||||
}
|
||||
/*
|
||||
if controller.ProcessCrashed(0.1) {
|
||||
log.Println("Process 2 crashed")
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
goto A2
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ package ewd123d
|
||||
|
||||
import (
|
||||
"../controller"
|
||||
"log"
|
||||
)
|
||||
|
||||
// global synchronization variables
|
||||
@ -32,6 +31,8 @@ func process1() {
|
||||
L1:
|
||||
c1 = 0
|
||||
if c2 == 0 {
|
||||
//when both processes are at this stage, they will wait for each other to clear this area
|
||||
//for this to happen the processes need to be executed at exactly the same time.
|
||||
c1 = 1
|
||||
goto L1
|
||||
}
|
||||
@ -44,10 +45,10 @@ L1:
|
||||
|
||||
controller.OutsideCriticalSection(1, 100)
|
||||
|
||||
if controller.ProcessCrashed(0.1) {
|
||||
/*if controller.ProcessCrashed(0.1) {
|
||||
log.Println("Process 1 crashed")
|
||||
return
|
||||
}
|
||||
}*/
|
||||
|
||||
goto L1
|
||||
}
|
||||
@ -69,10 +70,10 @@ L2:
|
||||
|
||||
controller.OutsideCriticalSection(2, 100)
|
||||
|
||||
if controller.ProcessCrashed(0.1) {
|
||||
/*if controller.ProcessCrashed(0.1) {
|
||||
log.Println("Process 2 crashed")
|
||||
return
|
||||
}
|
||||
}*/
|
||||
|
||||
goto L2
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ A1:
|
||||
c1 = 0
|
||||
L1:
|
||||
if c2 == 0 {
|
||||
//if both processes are stuck here, the turn variable will decide which process runs first
|
||||
if turn == 1 {
|
||||
goto L1
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user