multithreading - Singletons in multi threaded environment -
when using singletons, if class has instance fields should careful when several threads might using singleton? (and fields mutable , values can changed)
i havn't tried in theory seems answer yes , need synchronization (or skip singleton)
when access object (or same mutable data) multiple threads (or processes) need kind of synchronization. there no difference whether singleton or other "non-singleton" object.
one additional question, in case of singletons creation of singleton though, if created first time used, first time might concurrently different threads, need synchronize singleton-creation well.
Comments
Post a Comment