[libc-commits] [PATCH] D79828: [libc] Add implementation of call_once from threads.h.

Fangrui Song via Phabricator via libc-commits libc-commits at lists.llvm.org
Sat May 16 21:44:09 PDT 2020


MaskRay added a comment.

This is correct but slow, because there is always a futex syscall. A better approach is to add at least another state "initialization has finished". If the cas returns that state, don't bother calling wait. (It may also make sense to optimize the initial cas with an acquire load.)

This may also be a good example demonstrating that implementing pthread with C11 threads can cause duplication. In reality few applications use `call_once`. They all call `pthread_once`. For `pthread_once`, you need to think of pthread cancelling, which has to use more mechanism.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79828/new/

https://reviews.llvm.org/D79828





More information about the libc-commits mailing list