Bug ID: 36366
           Summary: value has not been synced in shared memory by
           Product: clang
           Version: 4.0
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs

Created attachment 19852
shared momery queue

My Mac gcc version info is as follows:

    Configured with: --prefix=/Applications/
    Apple LLVM version 9.0.0 (clang-900.0.39.2)
    Target: x86_64-apple-darwin16.7.0
    Thread model: posix

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

       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.
    Target: x86_64-redhat-linux
    Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=
--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
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64
    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.
llvm-bugs mailing list

Reply via email to