4 ms·
every language?
by merb 5y ago
every language?
- ptx 5y agoTo be fair, threads complicate things.
- merb 5y agoyeah but most languages have stuff like Atomic integers or other things.
- Kiro 5y agoI want a language where it's as natural as my example above, and normally an object or array so the integer was just to simplify the example. Do you have any suggestions? I want to declare a variable and then be able to access/modify the same variable through a closure in a callback for incoming requests, so I guess that requires it to be single-threaded. (I'm using this for game state where it's very convenient to just declare a persistent data structure in code directly without without having to use any additional abstraction.)
- merb 5y agowell without atomic access your state would be wrong. there are languages that allow stuff like that, but if you do it you can still have the wrong number. i.e. in c# something like you wrote is possible but when getting multiple requests, the number might be wrong at the end. you always have some tradeoffs because in your case when you would run it with a multi threaded js engine your variable would be as broken as the c# one. that's why java does not allow it by default to modify a variable inside a thread that is declared outside.