[Interest] Heavily Commented Example: Simple Single Frontend with Two BackendsLow,

d3fault d3faultdotxbe at gmail.com
Sat Oct 27 02:32:40 CEST 2012


Just about threw up when I woke up and realized what I had done (I
dream in code). Isn't the address of a stack object, when accessed
from another thread, not guaranteed to even be valid? Doesn't each
context/thread have it's own stack? I don't know, but it just seems
gross. The only justification I had for allocating it on the stack was
that it would be a stronger guarantee that when run() went out of
scope, the object would be deleted (like a QMutexLocker). The only
case I can think of where it would do that without continuing after
exec() is if terminate() is called. If you're terminating, you have
bigger problems than a leaked object on the heap.

So I changed it to now allocate the object on the heap instead. I am
not even sure it should have worked to begin with. Maybe I was just
getting lucky because I'm testing on a single core x86? No idea tbh,
but this change eases a pain in my stomach.

http://www2.zshare.ma/80wny0lnxfdt [also attached]

d3fault
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CleanThreadingExample.zip
Type: application/zip
Size: 18727 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121026/aa94afac/attachment.zip>


More information about the Interest mailing list