The Storm
22nd August 2010, 20:02
Lets say I have this sample code:
class MyThead : public QThread
{
public:
MyThead() {};
~MyThread {};
QString getTheString() const { return m_someString; }
protected:
void run()
{
// Do stuff with m_someString....
}
private:
QString m_someString;
}
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?
class MyThead : public QThread
{
public:
MyThead() {};
~MyThread {};
QString getTheString() const { return m_someString; }
protected:
void run()
{
// Do stuff with m_someString....
}
private:
QString m_someString;
}
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?