https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66842
--- Comment #7 from Richard Henderson <rth at gcc dot gnu.org> --- (In reply to Bin Fan from comment #6) > Could you clarify what does aliased pages mean? Do you mean the same object > is mapped into two or more different processes with different virtual > addresses? And the locks in libatomic are also shared by the processes? Or > something else? The same page mapped into the address space more than once. Of course I don't mean different processes, as libatomic is *not* an IPC library. Such a thing is easily constructable via mmap of a file, however. > This make sense if the above understand of aliased pages is true. However, > what if the memory is not mapped at page boundaries? How do you suppose you'd map a page anywhere other than at a page boundary? That's nonsensical. Virtual address spaces don't work that way. > And this does not explain why a locked object is protected by multiple > locks. If memory is always mapped at edge boundaries, then the offset of the > object in the page will always be the same so one lock should work. If > memory is not mapped at page boundaries, then if an object is mapped into > two "non-overlapped" address space inside a page, multiple locks would still > don't work. ... > Besides aliased pages, does libatomic consider supporting nested locked > atomic objects? For example, should the following work? > > typedef struct { > _Atomic locked1_t obj1; > /* other fields */ > } locked2_t; > > _Atomic locked2_t obj2; Yes. The end address cannot be inferred from the start address. Thus we lock every cacheline the object overlaps.