<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Crashing on pthread_join"
   href="http://llvm.org/bugs/show_bug.cgi?id=20003">20003</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Crashing on pthread_join
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>libclang
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>allan@comp.ufu.br
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=12638" name="attach_12638" title="source code">attachment 12638</a> <a href="attachment.cgi?id=12638&action=edit" title="source code">[details]</a></span>
source code

I think this is a bug. The code sounds sound and it works normally if I compile
with GCC.

The source code is attached. The file `in` is above. Ex:

$ gcc -ggdb -pthread thread.c
$ ./a.out < in
1 2 3 
4 5 6 

7 8 
9 10 
11 12 

BEFORE SLEEP
AFTER SLEEP
AFTER JOIN
58 64 
139 154 

Count: 4
$ clang -ggdb -pthread thread.c
$ ./a.out < in 
1 2 3 
4 5 6 

7 8 
9 10 
11 12 

BEFORE SLEEP
AFTER SLEEP
Segmentation fault (core dumped)
$

I suppose this is an bug in clang.

OS: Ubuntu 12.04.4 fully updated (Linux hostname 3.2.0-64-generic #97-Ubuntu
SMP Wed Jun 4 22:04:21 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux)

clang: Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM
3.0) Target: x86_64-pc-linux-gnu Thread model: posix

Proc: Intel i5 4 "cores"

===== BEGIN FILE "IN" =====
2 3
1 2 3
4 5 6
3 2
7 8
9 10
11 12

====== END FILE ======</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>