Changeset 471


Ignore:
Timestamp:
Feb 6, 2004, 11:26:36 AM (21 years ago)
Author:
Gary Byers
Message:

Keep the tcr around as long as possible (count down from
PTHREAD_DESTRUCTOR_ITERATIONS). Handle the case when a pthread can
no longer reveive signals but the underlying Mach thread still exists,
in suspend_tcr/resume_tcr.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/lisp-kernel/thread_manager.c

    r454 r471  
    435435    tcr->tlb_pointer[i] = (LispObj) no_thread_local_binding_marker;
    436436  }
    437 
     437  tcr->shutdown_count = PTHREAD_DESTRUCTOR_ITERATIONS;
    438438  return tcr;
    439439}
     
    456456  }
    457457 
    458   if (tcr->flags & (1<<TCR_FLAG_BIT_SHUTDOWN_REQUEST)) {
    459     tcr->flags &= ~(1<<TCR_FLAG_BIT_SHUTDOWN_REQUEST);
    460 
     458  if (--(tcr->shutdown_count) == 0) {
     459#ifdef DEBUG_THREAD_CLEANUP
     460    fprintf(stderr, "\nprocessing final shutdown request for pthread 0x%x tcr 0x%x", pthread_self(), tcr);
     461#endif
    461462#ifdef DARWIN
    462463    darwin_exception_cleanup(tcr);
     
    484485    tcr->osid = 0;
    485486  } else {
    486     tcr->flags |= (1<<TCR_FLAG_BIT_SHUTDOWN_REQUEST);
    487487    tsd_set(lisp_global(TCR_KEY), tcr);
     488#ifdef DEBUG_THREAD_CLEANUP
     489    fprintf(stderr, "\nprocessing early shutdown request for pthread 0x%x tcr 0x%x, tsd = 0x%x",
     490            pthread_self(), tcr, tsd_get(lisp_global(TCR_KEY)));
     491#endif
    488492  }
    489493}
     
    725729    current->flags |= (1<<TCR_FLAG_BIT_FOREIGN);
    726730    register_thread_tcr(current);
    727 
     731#ifdef DEBUG_TCR_CREATION
     732    fprintf(stderr, "\ncreating TCR for pthread 0x%x", pthread_self());
     733#endif
    728734    current->vs_area->active -= 4;
    729735    *(--current->save_vsp) = lisp_nil;
     
    746752  int suspend_count = atomic_incf(&(tcr->suspend_count));
    747753  if (suspend_count == 1) {
    748     pthread_kill((pthread_t)tcr->osid, thread_suspend_signal);
    749     SEM_WAIT(tcr->suspend);
    750   }
    751   return suspend_count == 1;
     754    if (pthread_kill((pthread_t)tcr->osid, thread_suspend_signal) == 0) {
     755      SEM_WAIT(tcr->suspend);
     756    } else {
     757      /* A problem using pthread_kill.  On Darwin, this can happen
     758         if the thread has had its signal mask surgically removed
     759         by pthread_exit.  If the native (Mach) thread can be suspended,
     760         do that and return true; otherwise, flag the tcr as belonging
     761         to a dead thread by setting tcr->osid to 0.
     762      */
     763#ifdef DARWIN
     764      if (mach_suspend_tcr(tcr)) {
     765        tcr->flags |= TCR_FLAG_BIT_ALT_SUSPEND;
     766        return true;
     767      }
     768#endif
     769      tcr->osid = 0;
     770      return false;
     771    }
     772    return true;
     773  }
     774  return false;
    752775}
    753776
     
    770793  int suspend_count = atomic_decf(&(tcr->suspend_count));
    771794  if (suspend_count == 0) {
     795#ifdef DARWIN
     796    if (tcr->flags & TCR_FLAG_BIT_ALT_SUSPEND) {
     797      tcr->flags &= ~TCR_FLAG_BIT_ALT_SUSPEND;
     798      mach_resume_tcr(tcr);
     799      return true;
     800    }
     801#endif
    772802    pthread_kill((pthread_t)tcr->osid, thread_resume_signal);
    773   }
    774   return (suspend_count == 0);
     803    return true;
     804  }
     805  return false;
    775806}
    776807
     
    799830  LOCK(lisp_global(TCR_LOCK), current);
    800831  for (other = current->next; other != current; other = other->next) {
    801     if (other->osid != 0) {
     832    if ((other->osid != 0)) {
    802833      suspend_tcr(other);
     834      if (other->osid == 0) {
     835        dead_tcr_count++;
     836      }
    803837    } else {
    804838      dead_tcr_count++;
     
    809843    for (other = current->next; other != current; other = next) {
    810844      next = other->next;
    811       if (other->osid == 0) {
     845      if ((other->osid == 0)) {
    812846        dequeue_tcr(other);
    813847        free(other);
Note: See TracChangeset for help on using the changeset viewer.