News for hackers. Stuff that matters.
Re:Landing a new syscall, part 1: What is futex? by im3w1l on Wednesday February 09, 2022 @10:27AM (#30273690)
The articles code for mutex_lock is this

  mutex_lock(unsigned int mutex)
  {
    while (!cmpxchg(&mutex, UNLOCKED, LOCKED))
      futex(&mutex, FUTEX_WAIT, LOCKED);
  }
Now consider what happens if someone calls it

  volatile unsigned int my_mutex = UNLOCKED;
  mutex_lock(my_mutex);
  ...
  mutex_unlock(my_mutex);
my_mutex is copied into the mutex parameter. The mutex parameter is updated to locked. mutex_lock exits, which destroys the mutex variable. my_mutex still has the variable UNLOCKED.
Re:Landing a new syscall, part 1: What is futex? by mfilion on Wednesday February 09, 2022 @10:52AM (#30274107)
Good catch, corrected!
Re:Landing a new syscall, part 1: What is futex? by waynesonfire on Wednesday February 09, 2022 @11:26AM (#30274544)
One more...

> We use &mutex as the first argument

Re:Landing a new syscall, part 1: What is futex? by andrealmeid on Wednesday February 09, 2022 @01:23PM (#30276167)
ops, fixed, thanks!