[Kde-devel-es] Matar hilos (QThread) con el tiempo

Aleix Pol aleixpol at kde.org
Tue May 19 20:29:12 CEST 2009


Porque no añades un metodo a tu thread que te permita modificar el estado
del thread para que el solito sepa que tiene que acabar? (devolver en el
metodo run).

2009/5/18 Laura Santiago de la Cal <lalii24 at hotmail.com>

>  Hola, tambien había probado anteriormente con terminate() (se me olvidó
> ponerlo) y tampoco me termina la ejecución del hilo...
> Y efectivamente no tengo un bucle de eventos en mi hilo, explico un poco
> porque quiero acabar con un hilo pasado X segundos.
> Resulta que estoy haciendo un "motor" que manejará hilos escritos por
> usuarios desconocidos para mi sistema, y lo que pretendo es que si este
> usuario quiere ejecutar su hio durante más tiempo que el que le otorgo no
> pueda y ese hilo sea desalojado...
>
> ¿Alguna otra idea? (Gracias Albert por contestar tan rápido)
>
> > From: aacid at kde.org
> > To: kde-devel-es at kde.org
> > Date: Sat, 16 May 2009 18:34:17 +0200
> > Subject: Re: [Kde-devel-es] Matar hilos (QThread) con el tiempo
>
> >
> > A Divendres, 15 de maig de 2009, Laura Santiago de la Cal va escriure:
> > > Hola, soy nueva en esta listasde distribución (me la recomendaron desde
> > > otra) y tengo un problema que he mirado por todas partes y no le
> encuentro
> > > solución, espero que alguno de ustedes me pueda orientar. Resulta que
> tengo
> > > un proceso que quiero que "guie" 2 hilos (QThread), para ello lo que
> quiero
> > > es que llame al primero e independientemente de porque parte de la
> > > ejecución se encuentre este hilo a los 5 segundos mate a este hilo y
> llame
> > > al segundo.
> >
> > No, no quieres hacer eso, matar un thread independientemente de la parte
> en la
> > que se encuentre es una MUY MALA práctica de programación.
> >
> > > ¿Alguien sabe como hacerlo? Lo que yo he intentado es lo
> > > siguiente, pero no funciona:
> > >
> > > //Los 2 procesos que compiten
> > > a = new clase() ; //clase herda de QThread
> > > b = new clase() ;
> > >
> > > //Controlamos los hilos hasta que hay un ganador
> > > while(get_win()==-1)
> > > {
> > >
> > > QTimer::singleShot(6, a, SLOT(quit()));
> > > QTimer::singleShot(6, b, SLOT(quit()));
> > > a->start();
> > > b->start();
> > > update();
> > > }
> >
> > No funciona porque
> >
> > void QThread::quit()
> > Tells the thread's event loop to exit with return code 0 (success).
> Equivalent
> > to calling QThread::exit(0).
> > This function does nothing if the thread does not have an event loop.
> >
> > Y más que probablemente tu thread no tenga un event loop.
> >
> > Si lo que quieres es matar el thread (ya te he dicho que no deberias
> hacerlo)
> > tienes
> >
> > void QThread::terminate()
> > Terminates the execution of the thread.
> > When the thread is terminated, all threads waiting for the thread to
> finish
> > will be woken up.
> > Warning: This function is dangerous and its use is discouraged. The
> thread can
> > be terminate at any point in its code path. Threads can be terminated
> while
> > modifying data. There is no chance for the thread to cleanup after
> itself,
> > unlock any held mutexes, etc. In short, use this function only if
> absolutely
> > necessary.
> >
> > Pues eso, que para 3 slots que tiene QThread no habias leido la
> documentación
> > con suficientes ganas.
> >
> > Albert
> >
> > >
> > > Muchas gracias por su tiempo
> > >
> > >
> > > _________________________________________________________________
> > > Comparte, crea, disfruta… Descubre todo, en estos vídeos
> > > http://www.windowslive.es
> >
> >
> > _______________________________________________
> > Kde-devel-es mailing list
> > Kde-devel-es at kde.org
> > https://mail.kde.org/mailman/listinfo/kde-devel-es
>
> ------------------------------
> Ahora, GRATIS Hotmail en tu móvil ¡Descúbrelo aquí!<http://serviciosmoviles.es.msn.com/hotmail.aspx>
>
> _______________________________________________
> Kde-devel-es mailing list
> Kde-devel-es at kde.org
> https://mail.kde.org/mailman/listinfo/kde-devel-es
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/kde-devel-es/attachments/20090519/09ab022e/attachment.htm 


More information about the Kde-devel-es mailing list