concurrency - Singleton and thread safety -



concurrency - Singleton and thread safety -

when talking singletons , threadsafe-ty issues concerning race conditions in creating singleton instance, thread talking about?

using example, assume have myapp uses singleton

class myapp { mysingleton oneandonly; int main() // application entry point { oneandonly = mysingleton::getinstance(); } void spawnthreads() { for(int = 0; < 100; i++) { thread spawn = new thread(new threadstart(justdoit)); spawn.start(); } } void justdoit() { waitrandomamountoftime(); // wait induce race status (maybe?) next line. mysingleton localinstance = mysingleton::getinstance(); localinstance.dosomething(); } }

is talking about:

when open myapp.exe once, , 1 time more again, trying have both opened? or talking threads spawned myapp? if myapp not spawn threads?

in windows threads exist solely within scope of process, i.e. running instance of application. thread safety means making sure shared resources accessed sequentially multiple threads within given process.

in more general terms, race conditions occur result of concurrency regardless of scope. illustration distributed application exposes shared resource external processes, still subject race conditions if access resource isn't regulated.

concurrency thread-safety singleton

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -