[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



Hej Michael

Michael Rasmussen wrote:
Peter Maersk-Moller <sslug@sslug> wrote:
Men selv select() er blokeret .. men der er vist en timer på. Så
måske ved brug af select(), behøver jeg ikke at bruge KillThread.
Hvorfor opretter du ikke dine tråde detach? De vil så slå sig selv
ihjel ved exit, og give kernen besked om at frigive alle deres
ressourcer. Se
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/index.htm?info/apis/users_16.htm

Hmm, jeg er lidt usikker, men mener det er der flere grunde til, at jeg ikke gør. Først og fremmest bruger jeg threads gennem libSDL for at få et nogenlunde ensartet interface til threads på forskellige platforme.

Da jeg bruger libSDL er jeg lidt i tvivl om, hvormeget libSDL kan kombineres med brug af pthreads direkte uden at bryde med portabiliteten. Dernæst er en del ting i pthreads i Linux vist ikke helt POSIX compliant og næppe nemt portabel til andre platforme.

Men ressourcerne kan jeg næsten selv rydde op bag efter, men jeg er i tvivl om, hvad der sker præcist, når jeg sender en pthread_cancel() (SDL_KillThread()) til en thread, der er blokeret på en read(fd, buffer..) eller write(fd,buffer..) og hvad sker der, hvis jeg umiddelbart efter at have sendt destroy_thread laver en close(fd) og bagefter en free(buffer). Kan jeg være sikker på, at tråden med read(fd,buffer..) ER STOPPET, når jeg returnerer fra pthread_cancel() (SDL_KillThread()) og jeg derfor godt kan udføre free(buffer) ?

SDL siger selv

  SDL_KillThread  gracelessly terminates the thread associated
  with thread. If possible, you should use some other form of
  IPC to signal the thread to quit.

gracelessly kan jo indeholde hvad som helst og garanterer jo ikke nødvendigvis at tråden ER termineret, når SDL_KillThread() returnerer.

mvh.

Peter



 
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] *