Skip to content

rhpo/gosem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

A Go SE2 (L3/ISIL) Semaphore Simulation

Installation

go get -u https://github.com/rhpo/gosem

Code Example (Classic Pont Semaphore)

package main

import (
	"fmt"
	. "github.com/rhpo/gosem"
)

var (
	pont      = NomSemaphore()
	SemNbNord = NomSemaphore()
	SemNbSud  = NomSemaphore()
)

func main() {
	I(pont, 1)
	I(SemNbNord, 1)
	I(SemNbSud, 1)

	nbNord := 0
	nbSud := 0

	// Processus Nord
	Repeat(5, func() {
		Process(func() {

			P(SemNbNord)

			nbNord++
			if nbNord == 1 {
				P(pont)
			}

			V(SemNbNord)

			fmt.Println("Une voiture nord a passé")

			nbNord--
			if nbNord == 0 {
				V(pont)
			}

		})
	})

	// Processus Sud
	Repeat(5, func() {
		Process(func() {

			P(SemNbSud)

			nbSud++
			if nbSud == 1 {
				P(pont)
			}

			V(SemNbSud)

			fmt.Println("Une voiture sud a passé")

			nbSud--
			if nbSud == 0 {
				V(pont)
			}

		})
	})

	Wait()

}

A Small example is also available Here.

About

A Semaphore Simulation for Go intended for L3/ISIL Students.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages