QObject creating in one thread using in other
-
wrote on 21 Oct 2010, 17:06 last edited by
Passing signals back and forth between threads is thread save, accessing member variables of an object from another thread is not. So your application behaves exactly as expected.
-
wrote on 21 Oct 2010, 17:33 last edited by
Tobias, but simple reading member (without any operatinos from other threads on it) of object from another thread should not crash app.
-
wrote on 21 Oct 2010, 18:46 last edited by
[quote author="Denis Kormalev" date="1287682429"]Tobias, but simple reading member (without any operatinos from other threads on it) of object from another thread should not crash app.[/quote]
You can you a QMutex to solve the writing part, afair...
-
wrote on 21 Oct 2010, 18:52 last edited by
danilocesar, it is part what I am saying of. As I think author doesn't have race conditions, but has some problems with accessing members. So I think source will be really good to help him.
-
wrote on 21 Oct 2010, 18:56 last edited by
Denis: Sure, but how do you guarantee that no other thread does some writing somewhere without using a mutex or something similar?
-
wrote on 21 Oct 2010, 19:03 last edited by
[quote author="Tobias Hunger" date="1287687383"]Denis: Sure, but how do you guarantee that no other thread does some writing somewhere without using a mutex or something similar?[/quote]
You don't, however you need to understand/know what your code is doing =)
I believe we will help better when sriky27 post some code...
-
wrote on 21 Oct 2010, 19:04 last edited by
Tobias, of course there are no guarantee, but I think that question is not about mutexes. Let's wait for authors response.
-
wrote on 21 Oct 2010, 19:07 last edited by
[quote author="Tobias Hunger" date="1287687383"]Denis: Sure, but how do you guarantee that no other thread does some writing somewhere without using a mutex or something similar?[/quote]
I thought this message was for me =/
-
wrote on 23 Oct 2010, 08:45 last edited by
Hi,
Thanks for the responses there I am currently stripping my project related content and creating a simple application to present here. To explain what I am doing.
My objective of creating and starting a new thread was to improve startup of my process, the thread purely constructs an QObject and returns it to the main thread. The thread dies after that.
I believe I should not have any race conditions there. No one else is trying to access the object.-Sriky
-
wrote on 23 Oct 2010, 10:29 last edited by
A commonly used trick to improved perceived startup performance is to create some objects using a singleshot QTimer. That way the complexity of multithreading can be avoided in some cases. Maybe that would be applicable to your setup, too.
-
wrote on 23 Oct 2010, 11:49 last edited by
well i have tried it, i have two objects which take about 2 sec for constructing each of them, i wanted improve on it, so that the objects gets constructed in parallel.
-Sriky
12/13