Results 1 to 5 of 5

Thread: QT3: accessing singletons from within threads

  1. #1
    Join Date
    Jan 2006
    Posts
    9
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default QT3: accessing singletons from within threads

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT3: accessing singletons from within threads

    Yes, if your singleton implementation is thread-safe. You will need some locking mechanism like QMutex.

  3. #3
    Join Date
    Jan 2006
    Posts
    9
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QT3: accessing singletons from within threads

    Even if there's no shared data in the singleton?
    Last edited by karye; 31st March 2006 at 16:27.

  4. #4
    Join Date
    Jan 2006
    Posts
    9
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QT3: accessing singletons from within threads

    Answer from #qt: No, since it is reentrant.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT3: accessing singletons from within threads

    Quote Originally Posted by karye
    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.

Similar Threads

  1. Why do some QWidgets create own threads?
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 17:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.