Boost logo

Boost :

From: terekhov (terekhov_at_[hidden])
Date: 2002-01-15 09:10:29


--- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
[...]
> I think that if you can disable cancellation efficiently and
mutex_lock only
> throws cancellation exceptions, then there's no problem making
mutex_lock a
> cancellation point, since disabling cancellation effectively makes
it
> nothrow.
>
> If you can't disable cancellation efficiently (or, for example, if
that
> requires a mutex! - but I don't see why it would; that should be
> thread-local), then the problem gets more complicated.

http://sources.redhat.com/cgi-bin/cvsweb.cgi/pthreads/cancel.c?
rev=1.22&content-type=text/x-cvsweb-markup&cvsroot=pthreads-win32

int
pthread_setcancelstate (int state, int *oldstate)
     /*
      * ------------------------------------------------------
      * DOCPUBLIC
      * This function atomically sets the calling thread's
      * cancelability state to 'state' and returns the previous
      * cancelability state at the location referenced by
      * 'oldstate'
      *
      * PARAMETERS
      * state,
      * oldstate
      * PTHREAD_CANCEL_ENABLE
      * cancellation is enabled,
      *
      * PTHREAD_CANCEL_DISABLE
      * cancellation is disabled
      *
      *
      * DESCRIPTION
      * This function atomically sets the calling thread's
      * cancelability state to 'state' and returns the previous
      * cancelability state at the location referenced by
      * 'oldstate'.
      *
      * NOTES:
      * 1) Use to disable cancellation around 'atomic' code
that
      * includes cancellation points
      *
      * COMPATIBILITY ADDITIONS
      * If 'oldstate' is NULL then the previous state is not
returned
      * but the function still succeeds. (Solaris)
      *
      * RESULTS
      * 0 successfully set cancelability
type,
      * EINVAL 'state' is invalid
      *
      * ------------------------------------------------------
      */
{
  int result = 0;
  pthread_t self = pthread_self();

  if (self == NULL
      || (state != PTHREAD_CANCEL_ENABLE
          && state != PTHREAD_CANCEL_DISABLE))
    {
      return EINVAL;
    }

  /*
   * Lock for async-cancel safety.
   */
  (void) pthread_mutex_lock(&self->cancelLock);

  if (oldstate != NULL)
    {
      *oldstate = self->cancelState;
    }

  self->cancelState = state;

  /*
   * Check if there is a pending asynchronous cancel
   */
  if (self->cancelState == PTHREAD_CANCEL_ENABLE
      && self->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS
      && WaitForSingleObject(self->cancelEvent, 0) == WAIT_OBJECT_0)
    {
      ResetEvent(self->cancelEvent);
      (void) pthread_mutex_unlock(&self->cancelLock);
      ptw32_throw(PTW32_EPS_CANCEL);

      /* Never reached */
    }

  (void) pthread_mutex_unlock(&self->cancelLock);

  return (result);

} /* pthread_setcancelstate */

You might also want to have a look at this c.p.t thread:

http://groups.google.com/groups?as_umsgid=b859c232.0112190900.a3cb3d4%
40posting.google.com

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk