[Qt-interest] QT signal and reentrant

Paul Floyd paulf at free.fr
Tue Jun 16 13:39:13 CEST 2009


Quoting é&#8218;µåº¦ <shao.tu at gmail.com>:

> Thanks Paul.
>
> So, based on your explanation, my program not need to be "reentrant", and
> can read/write static data
> as long as I can manage it via something like mutex mechanism ( i.e. it's
> thread safety). Is that correct?

[replying to group]

It depends on what you're trying to achieve. For a general-purpose Qt app that
is multi-threaded, then the code needs to be thread safe (that is, safe for the
code to execute simultaneously on multiple threads). There is no need for your
code to be reentrant, which is a more stringent requirement (effectively that
the code can execute simultaneously even on the same thread).

You can achieve thread safety by avoiding globals/statics, and by using mutexes
otherwise. Reentrancy is more difficult as you are limited to only those
functions that are themselves reentrant, e.g., you can't use malloc [or new
which is generally based on malloc].

A+
Paul
-- 
Paul Floyd   http://paulf.free.fr



More information about the Qt-interest-old mailing list