Results 1 to 6 of 6

Thread: Question about atomic operation and Qt's data sharing.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Question about atomic operation and Qt's data sharing.

    Lets say I have this sample code:
    Qt Code:
    1. class MyThead : public QThread
    2. {
    3. public:
    4. MyThead() {};
    5. ~MyThread {};
    6.  
    7. QString getTheString() const { return m_someString; }
    8.  
    9. protected:
    10. void run()
    11. {
    12. // Do stuff with m_someString....
    13. }
    14.  
    15. private:
    16. QString m_someString;
    17. }
    To copy to clipboard, switch view to plain text mode 

    If for example I call getTheString() method using other thread context will I get crash or something nasty if I do not synchronize m_someString with mutex? I had read about the reentrant and atomic reference counter in Qt but I'm still not sure if I get it right.

    On my project I have created an implicitly shared class using the QSharedData technique and I have lots of members that are mixed primitive types and Qt types. The big question here is can I share copy instances of my class without the need of mutex or other type locking?
    Last edited by The Storm; 22nd August 2010 at 21:25.

Similar Threads

  1. urgent!!!!!......sharing data
    By alphajoseph in forum Newbie
    Replies: 9
    Last Post: 16th September 2010, 11:42
  2. QVector::data() and implicit sharing
    By abernat in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2009, 18:34
  3. Sharing data between objects
    By Mr_Grieves in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2009, 00:13
  4. Sharing data between threads
    By bbui210 in forum Qt Programming
    Replies: 15
    Last Post: 19th October 2008, 17:56
  5. Sharing data across threads
    By jphn_crichton in forum Qt Programming
    Replies: 11
    Last Post: 5th May 2008, 18:29

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.