sb

package
v0.0.0-...-21ef4fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 5 Imported by: 0

README

The Sleeping Barber Problem

  • A classic computer science problem introduced by Djikstra in 1965.
  • A barber goes to a barbershop with a waiting room with a fixed number of seats.
  • If no one is in the waiting room, the barber goes to sleep.
  • When a client shows up, if there are no seats available, he or she leaves.

Solving the Problem


Documentation

Index

Constants

View Source
const (
	AVAILABLE_SEATS int = 5
	DAILY_CUSTOMERS int = 25
	CUTTING_TIME        = 5 * time.Second
)

Hard constants

View Source
const (
	EVENT_SHOP_OPEN int = iota
	EVENT_CUSTOMER_ARRIVAL
	EVENT_CUSTOMER_DEPARTURE
	EVENT_SEATING_VACANT
	EVENT_JOB_COMPLETION
	EVENT_SHOP_CLOSE
)

Shop Events

Variables

View Source
var SHOP_SERVICES = []string{"Haircut", "Shave", "Facial", "Bleaching", "Massage", "Hair Colouring"}

Functions

func SleepingBarber

func SleepingBarber()

The main Sleeping Barber Function

Types

type Barber

type Barber struct {
	// contains filtered or unexported fields
}

type BarberShop

type BarberShop struct {
	// contains filtered or unexported fields
}

func (*BarberShop) ExecuteJob

func (shop *BarberShop) ExecuteJob(j *Job, mutex *sync.Mutex)

Start a Job

func (*BarberShop) HandleBarberShopEvents

func (shop *BarberShop) HandleBarberShopEvents()

Handle BarberShop events: Events listen for BarberShop Activities

func (*BarberShop) Open

func (shop *BarberShop) Open()

Open shop

func (*BarberShop) PerformShopActivities

func (shop *BarberShop) PerformShopActivities()

Perform the BarberShop Activities

type Customer

type Customer struct {
	// contains filtered or unexported fields
}

type Event

type Event struct {
	// contains filtered or unexported fields
}

type Job

type Job struct {
	// contains filtered or unexported fields
}

type Jobs

type Jobs struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL