Qt-interest Archive, September 2002
Qt and multithreading using clone() system call
Message 1 in thread
I'm currently trying to use the clone() system call to add a thread to my
program, using:
if((pid = clone(&EpanList::socket_loop,stack+CHILD_STACK_SIZE/2,SIGCHLD |
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND,NULL))!=-1)
However when I try to use the "this" value in the function, which clone calls
(socket_loop in my example), the thread exits (possibly crashes). Isn't it
possible to make it work?
A workaround I've found is to pass the object as a parameter, but this causes
problems when trying to convert a QDateTime to a QString, it works with
Qt::LocalDate but not with Qt::TextDate... This could be worked around if
there was a way to make the main thread execute the update function, but I
can't seem to figure that one out either...
--
[ signature omitted ]
Message 2 in thread
On czwartek 05 wrzesień 2002 10:40 am, Simon Ejsing wrote:
> I'm currently trying to use the clone() system call to add a thread to my
> program, using:
> if((pid = clone(&EpanList::socket_loop,stack+CHILD_STACK_SIZE/2,SIGCHLD |
> CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND,NULL))!=-1)
You shouldn't really use clone() in xlib applications unless you know exactly
what you're doing. It seems the problems you've run into are due to
uncontrolled memory sharing.
You're much better off using either:
QProcess class if you want to execute system commands, or
QThread class if you want to use threads in your application.
Cheers, Kuba Ober