[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



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;
}

Thread_1 :
  block_for_signal(mysignal);
  signal_received = false;
  signal(mysignal, signal_func);
  while (1) {
    if (signal_receieved) {

      // Her er vi faktisk i en thread safe mutex periode .....
      // dvs i en kritisk beskyttet region
        signal_received = false;
        SDL_SemPost(sem);
      // Her forlader vi saa den kritiske region,
      // dvs.ikke laengeremutex thread safe

      unblock_signal(mysignal);
    }
    SDL_Delay(some_time);
  }

Thread_2 :
  unblock_for_signal(mysignal);
  while (1) {
    SDL_SemWait(sem);
    Do_something();
  }

Besvaerligt og granulariteten er begraenset af some_time i SDL_Delay(), men ellers virksomt. Thrad_2 er bare med som eksempel paa, at vi skal bruge en mutex som reaktion paa et signal.

P.



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