[LLVMbugs] [Bug 12158] New: sig 11 sometimes when accessing std::cout from multiple threads.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Mar 1 20:08:26 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=12158

             Bug #: 12158
           Summary: sig 11 sometimes when accessing std::cout from
                    multiple threads.
           Product: libc++
           Version: unspecified
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: seth.cantrell at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


I'm running:

#include <thread>
#include <mutex>
#include <iostream>
#include <future>
#include <vector>

std::mutex m;

struct lockostream {
    //std::lock_guard<std::mutex> l;
    //lockostream() : l(m) {}
};

std::ostream &operator<<(std::ostream &os,lockostream const &l) {
    return os;
}

int main()
{
    std::vector<std::future<void>> v;
    for(int i=0;i<200;++i) {
        v.push_back(std::async([&](int t){
            std::cout << lockostream() <<  t << ' ';
            std::cout << lockostream() <<  t << '\n';

        }
        ,i));
    }
}

Results obviously are not reliable, but it sometimes segfaults:


⑆ clang++ -std=c++11 -I ../libcxx/include -L ../libcxx/lib -lc++
-fcatch-undefined-behavior -ftrapv -Wall -Werror -pedantic automata.cpp &&
./a.out
0 0
12  12
3
 435 
 465
7 
8 96 171 
811
019
1 121 3
416 1151 1  1718 0192112222 2
 12
Segmentation fault: 11


I could be wrong but my understanding is that access to the standard streams
should be thread safe (though likely to be scrambled).

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list