Coder Social home page Coder Social logo

rihib / lamport-clock-simulator Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 7 KB

Simulate Lamport Clock with CLI

Home Page: https://doi.org/10.1145/359545.359563

Go 100.00%
c cli-app concurrent-programming distributed-systems golang happens-before lamport-clock logical-clocks multiprocessing multithreading mutual-exclusion simulator socket-programming

lamport-clock-simulator's Introduction

Lamport Clock Simulator

What is Lamport Clock?

Lamport Clock is a logical clock used to determine the order of events in a distributed system. It was introduced by Leslie Lamport in 1978[1]. It is not a physical clock but a logical clock that helps to determine the order of events in a distributed system.

Lamport Clocks are used to establish a partial ordering of events in a distributed system. Each process in the system maintains a logical clock that is incremented for each event it generates. When a process sends a message, it includes its logical clock value in the message. When a process receives a message, it updates its logical clock value to be greater than the maximum of its current value and the value in the received message.

[1] Leslie Lamport. 1978. Time, clocks, and the ordering of events in a distributed system. Commun. ACM 21, 7 (July 1978), 558โ€“565. https://doi.org/10.1145/359545.359563

How to use this implementation?

This implementation simulates the operation of the Lamport clock with the CLI.

Setting up the environment

git clone https://github.com/rihib/lamport-clock-simulator.git
cd lamport-clock-simulator
go run main.go 9000
go run main.go 9001 // Open a new terminal
go run main.go 9002 // Open a new terminal

Running the simulation

You can send and receive messages and perform computation events and see how the Lamport Clock value changes each time you do so.

// Terminal 1
% go run main.go 9000
Please type event, c or s: c
Calculate Event Success!!
Time: 1

Please type event, c or s: c
Calculate Event Success!!
Time: 2

Please type event, c or s: s
Please type the destination port: 9001
Sending Event Success!!
Time: 3

Please type event, c or s:
// Terminal 2
% go run main.go 9001
Please type event, c or s:
Message Received!!
Time: 4

Please type event, c or s:

lamport-clock-simulator's People

Contributors

rihib avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.