Grofit
December 18th, 2009, 02:21 AM
Hey,
I was having a conversation with a guy at work the other day and we were talking about singletons and he mentioned that only one thread can access a singleton at any given time, so the entire class/instance is entirely locked out to any other threads...
Im currently working on a distributed node system, so i have lots of apps that can sit on various servers and just wait to be sent information then process it and send it back. Now a few of these use singletons to manage cached collections of related data but as the requests come asynchronously and apparently static and singleton classes cannot allow multiple threads to use them at the same time (even with manual lock handling in place) i just wanted to see if anyone could shed any more light on this. As ideally i want multiple threads and be able to read from these singletons as there is more reads than there are writes...
The other reason i ask is because im writing quite a few Extension methods, and im wondering if they suffer from the same problem... im hoping its hogwash and you can use singletons and just put your own locking mechanisms in place, but like always im sure im wrong :(
I was having a conversation with a guy at work the other day and we were talking about singletons and he mentioned that only one thread can access a singleton at any given time, so the entire class/instance is entirely locked out to any other threads...
Im currently working on a distributed node system, so i have lots of apps that can sit on various servers and just wait to be sent information then process it and send it back. Now a few of these use singletons to manage cached collections of related data but as the requests come asynchronously and apparently static and singleton classes cannot allow multiple threads to use them at the same time (even with manual lock handling in place) i just wanted to see if anyone could shed any more light on this. As ideally i want multiple threads and be able to read from these singletons as there is more reads than there are writes...
The other reason i ask is because im writing quite a few Extension methods, and im wondering if they suffer from the same problem... im hoping its hogwash and you can use singletons and just put your own locking mechanisms in place, but like always im sure im wrong :(