[Interest] Write from different thread

Marc Mutz marc.mutz at kdab.com
Thu Aug 23 13:21:39 CEST 2012


Hi Giuseppe,

I think you got the categories wrong.

On Thursday August 23 2012, Giuseppe D'Angelo wrote:
> Now we have:
> 1) non-reentrant: safe to be used by only one thread

non-reentrant means: no other thread may execute this function while you're 
calling it.

> 2) reentrant: safe to be used by multiple threads, provided that
> access is serialized ("one at a time")

reentrant means: multiple threads may call this function at the same time, 
provided the input is different (for member functions, the instance (*this) 
is input, too!).

If you can serialise access (_all_ access), you can even call non-rerentrant 
functions from multiple threads; the problem is that you usually don't 
control all access points, so you can't secure them all. As is the case with 
QObject event handling - you'd at a minimum have to reimplement event() to 
lock the mutex, but code can also call functions through your meta object, 
and you don't control the lifetime of the references you hand out to it, so 
you cannot lock the mutex since you don't know when to unlock again.

> 3) thread-safe: safe to be used by multiple threads, even at the same time

thread-safe means: multiple threads may call this function at the same time, 
even with the same input (for member functions, that includes "on the same 
instance").

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-Independent Software Solutions



More information about the Interest mailing list