[llvm-bugs] [Bug 36366] New: value has not been synced in shared memory by __sync_val_compare_and_swap

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 13 07:34:37 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36366

            Bug ID: 36366
           Summary: value has not been synced in shared memory by
                    __sync_val_compare_and_swap
           Product: clang
           Version: 4.0
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: alexstocks at foxmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 19852
  --> https://bugs.llvm.org/attachment.cgi?id=19852&action=edit
shared momery queue

My Mac gcc version info is as follows:

    Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr
--with-gxx-include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 9.0.0 (clang-900.0.39.2)
    Target: x86_64-apple-darwin16.7.0
    Thread model: posix
    InstalledDir:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin


The attachment is a shared memory queue project. The queue may be visited by
many processes. The test file exam/test_mmap_queue.c introduces how to use it. 
The problem I wanna report is that a variable in the shared memory increased by
one process by __sync_val_compare_and_swap can not be visited by another
process. When I run this project on centos7 by gcc 4.8.5, the other process
will get the right value.

Let me illustrate how to reproduce the problem I meet.

Firstly, uncompress the attachment by command ' tar -jxf shmq.tar.bz2'.
Secondly, enter the project directory shm_queue and compile it by command '
make '. 
Thirdly, run the example by command ' ./bin/test_mmap_queue create /tmp/test1
32 10000 '. (If you run the command the second time, the command should be ' 
./bin/test_mmap_queue open /tmp/test1 '.)
Fourthly, enter the command ' get 2 20 ' to generate two subprocesses to get
total 20 elements from the shared memory queue, and the the output is as
follows.

       pidnum:0, oldpid:0, pid:10750, start to double cas
       cas loop, oldpid:0 pid:10750, sigidx:0, new pidnum 1
       pid:10750, mkfifo(fifo:/tmp/test1_fifo_0) = 3
       child 1 10750 event_fd=3
       pid:10751, pidnum:0 0

       pidnum:0, oldpid:10750, pid:10751, start to double cas
       cas loop, oldpid:10750 pid:10751, sigidx:0, new pidnum 1
       pid:10751, mkfifo(fifo:/tmp/test1_fifo_0) = 3
       child 2 10751 event_fd=3

The output related codes is in function src/mmap_queue.c:mq_get_eventfd. And
the related clang bug is on line src/mmap_queue.c:262. When process 10750
change the value of variable @head->pidnum from 0 to 1 and @head->pidset[0]
from 0 to 10750, the process 10751 got the value of @head->pidnum is 0 which
should be 1.

My centos 7 gcc version info is as follows:

    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
    Target: x86_64-redhat-linux
    Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id --with-linker-hash-style=gnu
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin
--enable-initfini-array --disable-libgcj
--with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install
--with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64
--build=x86_64-redhat-linux
    Thread model: posix
    gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)

Run the program as the above steps. And I can get the right output:

    pid:17291, pidnum:0 0
    pidnum:0, oldpid:12669, pid:17291, start to double cas
    cas loop, oldpid:12669 pid:17291, sigidx:0, new pidnum 1
    pid:17291, mkfifo(fifo:/tmp/test1_fifo_0) = 3
    pid:17290, pidnum:1 1
    pidnum:1, oldpid:12668, pid:17290, start to double cas
    cas loop, oldpid:12668 pid:17290, sigidx:1, new pidnum 2
    pid:17290, mkfifo(fifo:/tmp/test1_fifo_1) = 3
    child 2 17291 event_fd=3
    child 1 17290 event_fd=3

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180213/06bd87d8/attachment.html>


More information about the llvm-bugs mailing list