• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    Java
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Game of Life implemented in Java using virtual threads and communicating sequential processes

Game of Life CSP

Game of Life CSP is a Java implementation of Conway's Game of Life using communicating sequential processes (CSP).

Each grid cell is an independent process and all cell communication occurs via channels.

It's built atop virtual threads, defined in JDK Enhancement Proposal (JEP) 425.

The virtual threads feature is part of Project Loom.

Prior to Project Loom and virtual threads, CSP style programming in this manner simply wasn't available in Java.

Channels

Build

A Project Loom or OpenJDK 19 early access build is required at the time of writing.


Build with mvn:

mvn compile

Run:

java --enable-preview -cp target/classes/ gameoflife.Main

Compile with javac:

javac --enable-preview -source 19 src/main/java/gameoflife/*.java -d build/

Run:

java --enable-preview -cp build/ gameoflife.Main

Gosper Glider Gun

Command Line Arguments

Command line arguments are optional.

java --enable-preview -cp target/classes/ gameoflife.Main patterns/spaceship.txt 1800 1200 20 50 50 5 5 false true
  1. Pattern text file, ex. patterns/spaceship.txt
  2. Maximum window width, ex. 1800
  3. Maximum window height, ex. 1200
  4. Game of Life simulation period milliseconds, ex. 25
  5. Left padding columns, ex. 50
  6. Top padding rows, ex. 50
  7. Right padding columns, ex. 5
  8. Bottom padding rows, ex. 5
  9. Rotate boolean flag, ex. false
  10. Log rate boolean flag, ex. true

Patterns

The patterns directory contains text-encoded patters taken from Life Lexicon located at: https://people.sc.fsu.edu/~jburkardt/m_src/exm/lexicon.txt

The lexicon is copyright (C) Stephen Silver, 1997-2005.

The full list of contributors can be found under the credits section of the website.

Processes

Every cell runs in its own process, defined in Cell.java. Cell processes communicate with each other via channels.

The simulation runs in its own process, defined in GameOfLife.java.

Finally, the viewer runs in its own process, defined in Main.java.

  • Cell processes: R * C
  • Simulation processes: 1
  • Viewer processes: 1
  • Total processes: R * C + 2

Channels

A pair of channels, one in each direction, exists for every pair of neighbor cells.

  • Vertical segments: (C - 1) * R
  • Horizontal segments: (R - 1) * C
  • Interior vertices: (R - 1) * (C - 1)
  • Total cell-to-cell channels: [2 * (C - 1) * R] + [2 * (R - 1) * C] + [4 * (R - 1) * (C - 1)]

Additionally, each cell has a channel for receiving a tick event and and a channel for emitting results after each simulation tick.

  • Tick channels: R * C
  • Result channels: R * C

Finally, a channel is used to communicate a full liveness matrix to the main application consumer.

  • Total channels: 2 * (C - 1) * R + 2 * (R - 1) * C + 4 * (R - 1) * (C - 1) + R * C * 2 + 1

Benchmark

The following command results in a grid of 50,000 cells (250 x 200):

That results in 50,002 virtual threads and 497,305 channels.

java --enable-preview -cp target/classes/ gameoflife.Main patterns/puffer_train.txt 1600 800 0 235 91 10 91 true true

It's a demonstration of the viability of virtual threads in a highly concurrent, computationally intensive application.

Puffer Train

More Repositories

1

microhttp

Fast, scalable, self-contained, single-threaded Java web server
Java
527
star
2

project-loom-c5m

Experiment to achieve 5 million persistent connections with Project Loom virtual threads
Java
357
star
3

java-httpserver-vthreads

Benchmarks for JDK HTTP Server running on Java 21 with Virtual Threads
Java
141
star
4

project-loom-comparison

A comparison of different methods for achieving scalable concurrency in Java
Java
65
star
5

minesweeper-csp

Minesweeper implemented in Java using virtual threads and communicating sequential processes
Java
50
star
6

minesweeper-go-csp

Minesweeper implemented in Go using Goroutines and communicating sequential processes
Go
25
star
7

TrippinOnTubs

A cross-platform endless-runner game implemented with C++ and built atop SDL2.
C++
18
star
8

project-loom-experiment

Echo client-server components to evaluate Project Loom virtual threads.
Java
17
star
9

earth-moon-model

A tabletop digital art project that models the Earth and Moon
Python
4
star
10

kotlin-echo-client

Echo client using Kotlin with Ktor networking library
Kotlin
2
star
11

minesweeper_ftxui

A Minesweeper adaption that consists of a timed game made up of rounds of increasing difficulty
C++
2
star
12

microhttp-client

Simple, synchronous, virtual-thread-ready HTTP client library
Java
2
star
13

noaatides

Python
1
star
14

buoy-twitter-bot

Buoy Twitter Bot
Python
1
star
15

java-nio-demo

Demonstration of idiomatic, single-threaded, event-driven Java NIO networking
Java
1
star
16

tidemeter

Python
1
star
17

synergy-one-tracker

LED matrix digital art piece displaying UMBS metrics
C++
1
star
18

wave-tracker-led-matrix

Wave Tracker LED Matrix Raspberry Pi Project
Python
1
star
19

clojure-minesweeper

The classic Microsoft Minecraft game implemented in Clojure.
Clojure
1
star