Home:ALL Converter>How to avoid shared state?

How to avoid shared state?

Ask Time:2017-04-13T02:37:26         Author:sidoshi

Json Formatter

I have read many times that I should avoid shared state to avoid race conditions either in asynchronous programming or in multi threading.

So for example if I had a program that kept fetching data from external server and updated an object in memory and on user request I would send that object from memory.

How would I change the behaviour of such program to not use shared state?

I can't think of any way that makes sense. Have I misunderstood the idea of not using shared state?

Author:sidoshi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/43377180/how-to-avoid-shared-state
yy