Sharing between two Threads
When I create two instances of a Qthread derived class and run both threads.
Which area/space do they share now?
I know, that using static makes it possible. But without static variables?
Just the pure QThread-class with "normal" private variables.
I know its a bit stupid but,..all my tests showed my that they dont share anything.
Example1:
I counted on both instances an int var (private). No problem.
Example2:
I declared a var in run() and done sth with it on both threads...no problem.
So where do they share sth?
Re: Sharing between two Threads
Threads share code and data space. Each thread has an own stack. QThread objects themselves don't share anything. If you declare a global variable, it will be visible by both threads. If you want to avoid that, you can use shared memory. In both cases you'll have to synchronize those threads (using a global mutex so you won't escape from globals or statics).
Re: Sharing between two Threads
Ahh thats what I wanted to hear. :)
I know that the theory says threads share...but i was confused with qthreads.
In case of qthreads i must explicit share sth via global var, static var or shared mem.