[swift-users] Is this really a race condition?

Edward Connell ewconnell at gmail.com
Wed Mar 1 16:21:15 CST 2017


The thread sanitizer on Linux is reporting that I have race conditions in
libswiftcore. I eliminated enough code down to this trivial example. Is
there really a race condition here or are these bogus errors?

let count = 1000
var items = [[UInt8]?](repeating: nil, count: count)

DispatchQueue.concurrentPerform(iterations: count) {
items[$0] = [UInt8](repeating: 7, count: 10)
}

My real scenario is retrieving data asynchronously, so I just threw in a
buffer assignment.

Thanks, Ed

==================
WARNING: ThreadSanitizer: data race (pid=30720)
  Read of size 8 at 0x7d9000008028 by thread T16:
    #0 memcpy <null> (libtsan.so.0+0x00000002617a)
    #1 _TwCcOs31_ClosedRangeIndexRepresentation <null>
(libswiftCore.so+0x00000027e0fa)

  Previous write of size 8 at 0x7d9000008028 by main thread:
    #0 memcpy <null> (libtsan.so.0+0x00000002617a)
    #1 _TwCcOs31_ClosedRangeIndexRepresentation <null>
(libswiftCore.so+0x00000027e0fa)

  Location is heap block of size 8032 at 0x7d9000008000 allocated by main
thread:
    #0 malloc <null> (libtsan.so.0+0x0000000254a3)
    #1 swift_slowAlloc <null> (libswiftCore.so+0x0000002ee3e5)

  Thread T16 (tid=30917, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x000000027577)
    #1 manager_workqueue_additem
/home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-16_04/swift-corelibs-libdispatch/libpwq/src/posix/manager.c:815
(libdispatch.so+0x00000007c6b1)

SUMMARY: ThreadSanitizer: data race ??:0 memcpy
==================
==================
WARNING: ThreadSanitizer: data race (pid=30720)
  Write of size 8 at 0x7d0c00015d80 by thread T16:
    #0 free <null> (libtsan.so.0+0x000000025819)
    #1 _TwXxOs31_ClosedRangeIndexRepresentation <null>
(libswiftCore.so+0x00000027e071)

  Previous write of size 8 at 0x7d0c00015d80 by main thread:
    #0 malloc <null> (libtsan.so.0+0x0000000254a3)
    #1 swift_slowAlloc <null> (libswiftCore.so+0x0000002ee3e5)

  Thread T16 (tid=30917, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x000000027577)
    #1 manager_workqueue_additem
/home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-16_04/swift-corelibs-libdispatch/libpwq/src/posix/manager.c:815
(libdispatch.so+0x00000007c6b1)

SUMMARY: ThreadSanitizer: data race ??:0 __interceptor_free
==================
==================
WARNING: ThreadSanitizer: data race (pid=30720)
  Write of size 8 at 0x7d900000a028 by thread T20:
    #0 free <null> (libtsan.so.0+0x000000025819)
    #1 _TZFSa11_copyBufferfRGVs22_ContiguousArrayBufferx_T_ <null>
(libswiftCore.so+0x00000010884e)

  Previous read of size 8 at 0x7d900000a028 by thread T17:
    #0 memcpy <null> (libtsan.so.0+0x00000002617a)
    #1 _TwCcOs31_ClosedRangeIndexRepresentation <null>
(libswiftCore.so+0x00000027e0fa)

  Thread T20 (tid=30921, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x000000027577)
    #1 manager_workqueue_additem
/home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-16_04/swift-corelibs-libdispatch/libpwq/src/posix/manager.c:815
(libdispatch.so+0x00000007c6b1)

  Thread T17 (tid=30918, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x000000027577)
    #1 manager_workqueue_additem
/home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-16_04/swift-corelibs-libdispatch/libpwq/src/posix/manager.c:815
(libdispatch.so+0x00000007c6b1)

SUMMARY: ThreadSanitizer: data race ??:0 __interceptor_free
==================
==================
WARNING: ThreadSanitizer: data race (pid=30720)
  Read of size 8 at 0x7d9000006028 by thread T23:
    #0 memcpy <null> (libtsan.so.0+0x00000002617a)
    #1 _TwCcOs31_ClosedRangeIndexRepresentation <null>
(libswiftCore.so+0x00000027e0fa)

  Previous write of size 8 at 0x7d9000006028 by main thread:
    #0 malloc <null> (libtsan.so.0+0x0000000254a3)
    #1 swift_slowAlloc <null> (libswiftCore.so+0x0000002ee3e5)

  Location is heap block of size 8032 at 0x7d9000006000 allocated by main
thread:
    #0 malloc <null> (libtsan.so.0+0x0000000254a3)
    #1 swift_slowAlloc <null> (libswiftCore.so+0x0000002ee3e5)

  Thread T23 (tid=30924, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x000000027577)
    #1 manager_workqueue_additem
/home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-16_04/swift-corelibs-libdispatch/libpwq/src/posix/manager.c:815
(libdispatch.so+0x00000007c6b1)

SUMMARY: ThreadSanitizer: data race ??:0 memcpy
==================
==================
WARNING: ThreadSanitizer: data race (pid=30720)
  Write of size 8 at 0x7d900002e000 by thread T19:
    #0 free <null> (libtsan.so.0+0x000000025819)
    #1 _TZFSa11_copyBufferfRGVs22_ContiguousArrayBufferx_T_ <null>
(libswiftCore.so+0x000000108859)

  Previous write of size 8 at 0x7d900002e000 by thread T20:
    #0 malloc <null> (libtsan.so.0+0x0000000254a3)
    #1 swift_slowAlloc <null> (libswiftCore.so+0x0000002ee3e5)

  Thread T19 (tid=30920, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x000000027577)
    #1 manager_workqueue_additem
/home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-16_04/swift-corelibs-libdispatch/libpwq/src/posix/manager.c:815
(libdispatch.so+0x00000007c6b1)

  Thread T20 (tid=30921, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x000000027577)
    #1 manager_workqueue_additem
/home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-16_04/swift-corelibs-libdispatch/libpwq/src/posix/manager.c:815
(libdispatch.so+0x00000007c6b1)

SUMMARY: ThreadSanitizer: data race ??:0 __interceptor_free
==================
==================
WARNING: ThreadSanitizer: data race (pid=30720)
  Write of size 8 at 0x7d9000004000 by thread T17:
    #0 free <null> (libtsan.so.0+0x000000025819)
    #1 _TZFSa11_copyBufferfRGVs22_ContiguousArrayBufferx_T_ <null>
(libswiftCore.so+0x00000010884e)

  Previous write of size 8 at 0x7d9000004000 by main thread:
    #0 malloc <null> (libtsan.so.0+0x0000000254a3)
    #1 swift_slowAlloc <null> (libswiftCore.so+0x0000002ee3e5)

  Thread T17 (tid=30918, running) created by main thread at:
    #0 pthread_create <null> (libtsan.so.0+0x000000027577)
    #1 manager_workqueue_additem
/home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-16_04/swift-corelibs-libdispatch/libpwq/src/posix/manager.c:815
(libdispatch.so+0x00000007c6b1)

SUMMARY: ThreadSanitizer: data race ??:0 __interceptor_free
==================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170301/e6e4b7dc/attachment.html>


More information about the swift-users mailing list