This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/38688] New: __sync_lock_test_and_set does not actually lock


I was looking for something like MSVC's InterlockedIncrement in gcc and found
the __sync_lock_test_and_set builtin.

I wrote a small test program:

  #include <stdio.h>
  int l;
  int main() {
    printf("%d\n",__sync_lock_test_and_set(&l,1));
  }

and when I look at the disassembly I get

  xchgl   l(%rip), %esi

in 64-bit mode and

  xchgl   l, %eax

in 32-bit mode.  Notably missing is the lock prefix.  I was expecting a lock
prefix since the builtin is called __sync_LOCK_test_and_set.  Should there not
be a lock here?


-- 
           Summary: __sync_lock_test_and_set does not actually lock
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: felix-gcc at fefe dot de
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38688


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]