JuliaInterop / Clang.jl

C binding generator and Julia interface to libclang
https://juliainterop.github.io/Clang.jl/
MIT License
219 stars 68 forks source link

Support `_Atomic` #394

Open Gnimuc opened 1 year ago

Gnimuc commented 1 year ago

It looks like _Atomic can be supported by simply using the @atomic macro: https://docs.julialang.org/en/v1/manual/multi-threading/#man-atomics

Need to study the memory model carefully to make sure both Julia's representation and C/C++'s representation are compatible.

emmt commented 1 year ago

If you use the @atomic macro for some structure member, the structure must be mutable.

emmt commented 1 year ago

I have just checked that using @atomic x::T in a (mutable) Julia structure seems to be a more correct replacement for C member defined as _Atomic T x; than declaring them as x::Threads.Atomic{T}. With @atomic alignemnt and size seems to be preserved which is not the case with Threads.Atomic{T} because the latter yields a reference to a mutable Julia object.