[libc-commits] [libc] [libc] make integration test malloc work properly when threaded (PR #151622)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Fri Aug 1 06:57:48 PDT 2025
jhuber6 wrote:
> > Does `fetch_add` not work here?
> > ```c
> > void *naive_bump(size_t s) {
> > s = ((s + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT;
> > void *mem = __scoped_atomic_fetch_add(&bump_ptr, s, __ATOMIC_RELAXED,
> > __MEMORY_SCOPE_DEVICE);
> > return (uint8_t *)mem + s - memory >= MEMORY_SIZE ? nullptr : mem;
> > }
> > ```
>
> It should work in this case but notice that the semantic is not exactly the same. With fetch-add, allocating a large memory will immediately destroy the bump while CAS allows others to survive.
You could do the same with an atomic load, but I don't think we need to worry about this since it's just for testing.
https://github.com/llvm/llvm-project/pull/151622
More information about the libc-commits
mailing list