I have a couple of threads were some operations can be done in a singleton.
Is it thread-safe to use singletons?
I have a couple of threads were some operations can be done in a singleton.
Is it thread-safe to use singletons?
Last edited by karye; 31st March 2006 at 14:06.
Yes, if your singleton implementation is thread-safe. You will need some locking mechanism like QMutex.
Even if there's no shared data in the singleton?
Last edited by karye; 31st March 2006 at 16:27.
Answer from #qt: No, since it is reentrant.
You can't have singleton without shared data. What about the instance itself? It is shared among all threads. Make sure it is created in a safe manner when two threads request it at the same time.Originally Posted by karye
If the instance does not use any data, it will be enough when all its methods will be re-entrant.
Bookmarks