I'm not quite sure what you mean, but returning the result essentially forces the function to generate a shell class of the state machine and returns an instance of the class. Each return of profitability is a return from the state machine. The individual instance returned by your method call will not be thread safe (you cannot iterate over multiple threads at the same time), but multiple calls will generate separate instances. These individual instances can be used by multiple threads, and thread safety in this case is determined by the safety of the class threads used by the counters (the cart methods in your case.)
source share