c++ - Qt: QList thread issue -
c++ - Qt: QList thread issue -
the doc says qlist reentrant. next code thread safe?
//worker thread ... if(mylist.size() == 0) { ... } //main thread foreach(qimage, mylist) { ... }
all ... parts have nil mylist. mylist object in 2 threads same object. thread safe?
if mylist const , hence accesses read only, thread safe.
but if in @ to the lowest degree 1 thread code doing non-const access on object, not thread safe.
to sure doing read-only operations, declare const reference on mylist , utilize 1 in concurrent code :
const qlist<qimage> & constmylist = mylist;
this has nil reentrancy. reentrancy tells if doing operations (read or write) on 2 different qlist instances in 2 different threads respectively, behavior defined.
for instance, non-reentrant class may utilize static functions/members in non-static methods. if these static functions/members not guarded, class methods not reentrant : when working on 2 independent objects, behavior can undefined.
however, qt doc says read-only operations on containers thread-safe. looking for.
c++ multithreading qt
Comments
Post a Comment