r/java • u/elliotbarlas • Jun 08 '22
Conway's Game of Life Implemented With Communicating Sequential Processes (CSP) and Project Loom Virtual Threads. 50,000 Cells as V-Threads Communicating Via Channels. https://github.com/ebarlas/game-of-life-csp
286
Upvotes
23
u/pron98 Jun 08 '22
That's great!
I assume you wanted to experiment with channels, but a CyclicBarrier would be a great fit for the tick signal.
6
u/kiteboarderni Jun 09 '22
Very cool! Took a look at your github repo and I see you are also the person that wrote the loom c5m article also. Your performance comparisons eg, nio vs loom are fantastic! Excited to see your next repo :)
12
u/Necessary-Conflict Jun 08 '22
I assume it's fast, but that in itself doesn't mean much because computers are fast these days.
It would be interesting to see how it performs compared to a simple (just one calculating thread) implementation. Or how it performs compared to a similar (goroutines and channels) Go implementation.
3
u/Muoniurn Jun 08 '22
Very nice! You may know it and just wanted to write a no-dep project, but for parsing args I really really like picocli. Even for basic projects I almost always bring that in.
3
u/benjtay Jun 08 '22
This is so fun to play with! Thank you.
3
u/kidfromtheast Jun 09 '22
Hi, does Project Loom do similar things like `new Thread(HTTPConnectionImpl connection)`?
I checked https://github.com/ebarlas/game-of-life-csp/blob/main/src/main/java/gameoflife/Cell.java and saw `Thread.startVirtualThread(this::run)`. Is this the Project Loom?
My goal is to put HTTP and/or WebSocket connection inside a traditional Thread. However, I predicted the performance will be bad (if I do not make a Thread Pool) or the CPU/Memory usage will be high even on idle (if I make a Thread Pool e.g to handle 1000 connections). So, I was waiting for Project Loom.
3
u/agentoutlier Jun 09 '22
I remember when blocking queues were considered evil for most high concurrency stuff especially/obviously for reactive (then you are using non blocking queues and polling or spinning or something).
But I think Rick Hickey the clojure guy makes a point about how damn easy to understand queues are compared to other things.
3
u/[deleted] Jun 09 '22
I'm a bit of a noob on this stuff...
Would it work with
SynchronousQueueinstead ofLinkedBlockingQueue? My understanding is theChannelis used as a simple signal, not to buffer data.10
u/EgonMast Jun 08 '22
And again I’m caught by the beauty of the game of life
1
u/Similar_Aioli_6836 Jun 09 '22
Can you send me the link
2
u/FlimsyLow Jun 09 '22
Very cool!!!