licel / jcardsim

https://jcardsim.org
222 stars 123 forks source link

Unexpected - Transient memory is bound to threadlocal, thus shared by two simulator instances #208

Open martinpaljak opened 1 year ago

martinpaljak commented 1 year ago

The way transient memory is handled, is not as expected.

Making two simulator instances and sending commands to each other, right now the state is shared, as transient memory seems to come from a threadlocal for some reason.

https://github.com/licel/jcardsim/blob/b54b18bade77eaaf93a57f86c764bb17c5854fef/src/main/java/com/licel/jcardsim/base/SimulatorSystem.java#L47

The result is that apple A gets the same state as applet B for transient arrays:

https://github.com/licel/jcardsim/blob/b54b18bade77eaaf93a57f86c764bb17c5854fef/src/main/java/com/licel/jcardsim/framework/JCSystemProxy.java#L101

because the instance() is coming from threadlocal:

https://github.com/licel/jcardsim/blob/3c913e43f4ce3b01531c0e6120bda7d3fdc24b78/src/main/java/com/licel/jcardsim/base/SimulatorSystem.java#L77-L78

What to do (other than have multiple threads), I'd say this is a bug, threading would mean concurrency, but I access to instances sequentially.