[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Terminering af tråde



fredag 28 Marts 2008 skrev Peter Maersk-Moller:
> Michael Rasmussen wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> > 
> > On Thu, 27 Mar 2008 16:50:31 +0100
> > Mads Bondo Dydensborg <sslug@sslug> wrote:
> > 
> >> Det er ikke den værste ide, ihvertfald, selvom signaler til tråde
> >> tidligere har været noget flaky under Linux. Jeg tror det er iorden
> >> nu.
> >>
> > POSIX pthreads er ikke signal safe.
> 
> Ud over at en del funktioner ikke er threadsafe, og ud over nedenstående 
> med mutex, hvad betyder så 'ikke signal safe' ?
> 
>    "It is not safe to call mutex functions from a signal handler.
>     In particular, calling pthread_mutex_lock or pthread_mutex_unlock
>     from a signal handler may deadlock the calling thread."
> 
> Men antager man at SDL_Semaphore er implementeret med mutex, og har man 
> brug for at tilgaa en kritisk region beskyttet med en form for mutex fra 
> en signal handler kan ovenstående vel klares med
> 
> void signal_func() {
>    block_for_signal(mysignal);
>    signal_received = true;
> }

Du roder dig ud i noget snavs, hvis du begynder at lave noget i en signal 
handler i et multitrådet program, som låser. Det bør du forsøge at undgå.

Det kan være svært, enig, men forsøg at undgå det. Og, som Peter skriver, brug 
pthread_kill til hver enkelt tråd.

Mvh

Mads

-- 
Mads Bondo Dydensborg.                               sslug@sslug
NT is a closed box of point tools linked by an untouchable matrix of
invisible semaphores. These bonds are surrounded by a blizzard of
mystifying, contradictory, and forever-changing OS documentation. 
Under an NT regime, almost all Unix users will lose the ability to 
exert low-level control over data and applications.



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2008-04-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *