[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: nptl 0.30



Ulrich Drepper <drepper redhat com> schrieb am 18.03.03 19:53:59:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Alexander Terekhov wrote:
> >>Just invert those lines to :
> >>
> >>lll_mutex_unlock (cbuffer->cond->__data.__lock); /* much better to call
> >>futex_wake() with the mutex unlocked */
> >>lll_futex_wake (futex, INT_MAX);
> > 
> > 
> > I think that it's sufficient to wake just one single thread 
> > here (in cleanup() for async.cancel region "wrapping" futex 
> > wait(); I guess).
> 
> No, it's not sufficient.  There might be a thread which cannot be woken
> because it arrived after the cond_signal o broadcast which might be woken.

I don't understand this. Would you please elaborate?

> 
> Again, this is cancellation we are talking about.  It is not a regular
> programming tool, it's far too costly.  It's used in exception
> situations only.

Basically, I mean: < illustration >

http://www.terekhov.de/DESIGN-futex-CV.txt-with-async.cancelable-wait.txt

-----------
// auto "context" object inside wait() or extra pthread_t's fields
struct cond_wait_context_t {
   pthread_cond_t*  cv;
   pthread_mutex_t* mutex;
   int              futex;
};

cond_wait_cleanup_handler(cond_wait_context_t* ctx)
{
  cond_wait_cleanup (ctx->cv, ctx->mutex, ctx->futex);
}

cond_wait_cleanup_handler2(cond_wait_context_t* ctx)
{
  cond_signal (ctx->cv);
}

cond_wait_timeout(cv, mutex, timeout)
{

  lock(cv->lock);
  mutex_unlock(mutex); // here or below

  ++cv->waiters[ EOC(cv->futex) == (context.futex = cv->futex) ];

  unlock(cv->lock); 
  // mutex_unlock(mutex);

  context.cv = cv;
  context.mutex = mutex;
  
  pthread_cleanup_push (cond_wait_cleanup_handler, &ctx);
  pthread_cleanup_push (cond_wait_cleanup_handler2, &ctx);

  enable_async_cancel();

  FUTEX WAIT (cv->futex, futex, timeout); 

  disable_async_cancel();

  pthread_cleanup_pop (0); // cond_wait_cleanup_handler2
  pthread_cleanup_pop (1); // cond_wait_cleanup_handler

}
-----------

regards,
alexander.

______________________________________________________________________________
Schon wieder Viren-Alarm? Bei WEB.DE FreeMail ist das kein Problem,
hier ist der Virencheck inklusive! http://freemail.web.de/features/?mc=021158





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]