[Qt-interest] Multithreading - yield function
Thiago Macieira
thiago.macieira at trolltech.com
Tue Sep 1 13:01:23 CEST 2009
Em Terça-feira 01 Setembro 2009, às 11:56:52, Patric escreveu:
> you are telling me that if I have two threads that are running, I really
> don't know when the second one will start executing in the middle of the
> code ? And stop also.
> This don't sound very cool.
That's correct. That's the definition of threading. It's not about being cool:
this is about what threading is.
Unless you insert some synchronisation primitives, like mutexes, wait
conditions and semaphores, you should assume that any and ALL other threads
are running in parallel to your code.
You should assume that any other thread can run between any two instructions
in your code. You should also assume that it runs in the middle of your
instructions, unless you specifically used an atomic operation.
For example, the following code:
extern int a, b, c;
a = b + c;
printf("%d\n", a);
is not thread-safe. The value of b or c could change asynchronously, which
would result in garbage in a. Also, the value of a may be overwritten.
Please read some books on threading before adventuring into it. If you don't
understand threading, don't use it -- read a lot on it *first*.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Product Manager - Nokia, Qt Development Frameworks
Sandakerveien 116, NO-0402 Oslo, Norway
Qt Developer Days 2009 | Registration Now Open!
Munich, Germany: Oct 12 - 14 San Francisco, California: Nov 2 - 4
http://qt.nokia.com/qtdevdays2009
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090901/0e4ed775/attachment.bin
More information about the Qt-interest-old
mailing list