PDA

View Full Version : QT3: accessing singletons from within threads



karye
31st March 2006, 14:00
I have a couple of threads were some operations can be done in a singleton.
Is it thread-safe to use singletons?

jacek
31st March 2006, 14:21
Yes, if your singleton implementation is thread-safe. You will need some locking mechanism like QMutex.

karye
31st March 2006, 15:05
Even if there's no shared data in the singleton?

karye
1st April 2006, 09:56
Answer from #qt: No, since it is reentrant.

jacek
1st April 2006, 11:05
Even if there's no shared data in the singleton?
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.

If the instance does not use any data, it will be enough when all its methods will be re-entrant.