all algorithms implemented

This commit is contained in:
Johannes Theiner 2020-03-09 14:04:05 +01:00
parent ab9573e500
commit 37568c556c
5 changed files with 210 additions and 9 deletions

View File

@ -32,7 +32,7 @@ func main() {
log.Printf("*** Start\n")
var variant = "a"
var variant = "dekker"
if len(os.Args[1:]) > 0 { // do we have arguments?
variant = os.Args[1]
}

View File

@ -13,6 +13,11 @@
package ewd123b
import (
"../controller"
"log"
)
// global synchronization variables
var c1, c2 = 1, 1
@ -24,10 +29,51 @@ func Start() {
// process1 simulates the behaviour of the first process
func process1() {
// TO DO
L1:
if c2 == 0 {
goto L1
}
c1 = 0
controller.EnterCriticalSection(1)
controller.InsideCriticalSection(1, 50)
controller.LeaveCriticalSection(1)
c1 = 1
controller.OutsideCriticalSection(1, 100)
if controller.ProcessCrashed(0.1) {
log.Println("Process 1 crashed")
return
}
goto L1
}
// process2 simulates the behaviour of the second process
func process2() {
// TO DO
L2:
if c1 == 0 {
goto L2
}
c2 = 0
controller.EnterCriticalSection(2)
controller.InsideCriticalSection(2, 50)
controller.LeaveCriticalSection(2)
c2 = 1
controller.OutsideCriticalSection(2, 100)
if controller.ProcessCrashed(0.1) {
log.Println("Process 2 crashed")
return
}
goto L2
}

View File

@ -13,6 +13,11 @@
package ewd123c
import (
"../controller"
"log"
)
// global synchronization variables
var c1, c2 = 1, 1
@ -24,10 +29,49 @@ func Start() {
// process1 simulates the behaviour of the first process
func process1() {
// TO DO
A1:
c1 = 0
L1:
if c2 == 0 {
goto L1
}
controller.EnterCriticalSection(1)
controller.InsideCriticalSection(1, 50)
controller.LeaveCriticalSection(1)
c1 = 1
controller.OutsideCriticalSection(1, 100)
if controller.ProcessCrashed(0.1) {
log.Println("Process 1 crashed")
return
}
goto A1
}
// process2 simulates the behaviour of the second process
func process2() {
// TO DO
A2:
c2 = 0
L2:
if c1 == 0 {
goto L2
}
controller.EnterCriticalSection(2)
controller.InsideCriticalSection(2, 50)
controller.LeaveCriticalSection(2)
c2 = 1
controller.OutsideCriticalSection(2, 100)
if controller.ProcessCrashed(0.1) {
log.Println("Process 2 crashed")
return
}
goto A2
}

View File

@ -13,6 +13,11 @@
package ewd123d
import (
"../controller"
"log"
)
// global synchronization variables
var c1, c2 = 1, 1
@ -24,10 +29,50 @@ func Start() {
// process1 simulates the behaviour of the first process
func process1() {
// TO DO
L1:
c1 = 0
if c2 == 0 {
c1 = 1
goto L1
}
controller.EnterCriticalSection(1)
controller.InsideCriticalSection(1, 50)
controller.LeaveCriticalSection(1)
c1 = 1
controller.OutsideCriticalSection(1, 100)
if controller.ProcessCrashed(0.1) {
log.Println("Process 1 crashed")
return
}
goto L1
}
// process2 simulates the behaviour of the second process
func process2() {
// TO DO
L2:
c2 = 0
if c1 == 0 {
c2 = 1
goto L2
}
controller.EnterCriticalSection(2)
controller.InsideCriticalSection(2, 50)
controller.LeaveCriticalSection(2)
c2 = 1
controller.OutsideCriticalSection(2, 100)
if controller.ProcessCrashed(0.1) {
log.Println("Process 2 crashed")
return
}
goto L2
}

View File

@ -13,6 +13,11 @@
package ewd123dekker
import (
"../controller"
"log"
)
// global synchronization variables
var c1, c2 = 1, 1
var turn = 1
@ -25,10 +30,71 @@ func Start() {
// process1 simulates the behaviour of the first process
func process1() {
// TO DO
A1:
c1 = 0
L1:
if c2 == 0 {
if turn == 1 {
goto L1
}
c1 = 1
B1:
if turn == 2 {
goto B1
}
goto A1
}
controller.EnterCriticalSection(1)
controller.InsideCriticalSection(1, 50)
controller.LeaveCriticalSection(1)
turn = 2
c1 = 1
controller.OutsideCriticalSection(1, 100)
if controller.ProcessCrashed(0.1) {
log.Println("Process 1 crashed")
return
}
goto A1
}
// process2 simulates the behaviour of the second process
func process2() {
// TO DO
A2:
c2 = 0
L2:
if c1 == 0 {
if turn == 2 {
goto L2
}
c2 = 1
B2:
if turn == 1 {
goto B2
}
goto A2
}
controller.EnterCriticalSection(2)
controller.InsideCriticalSection(2, 50)
controller.LeaveCriticalSection(2)
turn = 1
c2 = 1
controller.OutsideCriticalSection(2, 100)
if controller.ProcessCrashed(0.1) {
log.Println("Process 2 crashed")
return
}
goto A2
}