emacs-devel
[Top][All Lists]
Advanced

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

Re: SIGPROF + SIGCHLD and igc


From: Helmut Eller
Subject: Re: SIGPROF + SIGCHLD and igc
Date: Sat, 28 Dec 2024 19:08:18 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

On Sat, Dec 28 2024, Eli Zaretskii wrote:

>> If two threads are claiming a the same non-recursive lock concurrently,
>> then it's not an error.
>
> Oh, so you are saying that taking the lock twice is a fatal error only
> if that is done from the same thread?  Is that known for certain?

Ahem, now you're making be nervous.  I'll show the implementation
before I say something stupid:

/* LockClaim -- claim a lock (non-recursive) */

void (LockClaim)(Lock lock)
{
  int res;

  AVERT(Lock, lock);

  res = pthread_mutex_lock(&lock->mut);
  /* pthread_mutex_lock will error if we own the lock already. */
  AVER(res == 0); /* <design/check/#.common> */

  /* This should be the first claim.  Now we own the mutex */
  /* it is ok to check this. */
  AVER(lock->claims == 0);
  lock->claims = 1;
}

/* LockClaimRecursive -- claim a lock (recursive) */

void (LockClaimRecursive)(Lock lock)
{
  int res;

  AVERT(Lock, lock);

  res = pthread_mutex_lock(&lock->mut);
  /* pthread_mutex_lock will return: */
  /*     0 if we have just claimed the lock */
  /*     EDEADLK if we own the lock already. */
  AVER((res == 0) == (lock->claims == 0));
  AVER((res == EDEADLK) == (lock->claims > 0));

  ++lock->claims;
  AVER(lock->claims > 0);
}

> Are we sure MPS must take the lock before it can stop registered
> threads?

Now that's a question for the MPS mailing list.

Helmut



reply via email to

[Prev in Thread] Current Thread [Next in Thread]