<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rtc="http://microsoft.com/officenet/conferencing" xmlns:D="DAV:" xmlns:Repl="http://schemas.microsoft.com/repl/" xmlns:mt="http://schemas.microsoft.com/sharepoint/soap/meetings/" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ppda="http://www.passport.com/NameSpace.xsd" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcs="http://schemas.microsoft.com/data/udc/soap" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:udcp2p="http://schemas.microsoft.com/data/udc/parttopart" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:dsss="http://schemas.microsoft.com/office/2006/digsig-setup" xmlns:dssi="http://schemas.microsoft.com/office/2006/digsig" xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:spwp="http://microsoft.com/sharepoint/webpartpages" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:pptsl="http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/" xmlns:spsl="http://microsoft.com/webservices/SharePointPortalServer/PublishedLinksService" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">We have implemented a tool based on clang at Autodesk to help developers express their design decisions. The basic idea is the design decisions implemented
 as a set of customized GNU style attributes can serve as metadta to the fuctions, classes, etc and these metadata could be checked by clang static analyzer to enforce specific data access pattern and call graph for functions. We use this tool to help us parallelize
 some of our legacy C++ code base, for example, by enforcing a specific code is purely functinal style thus by definition is trivially thread safe.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Our implementation touches many pieces of clang as we don’t find a less intrusive way to get the attributes / metadata into clang’s type system and AST. As
 a result we have to periodically merge our code base with Clang official trunk, which sometimes is quite touch. The checker is easy to write as it is very well decoupled from the rest of the system.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I am wondering if this project would lead to an extensible annotation framework for Clang so user could encode arbitary metadata into Clang AST. That would
 be very useful and powerful for analysis code as it would involve develpers more intimately by capturing the design decisions eariler.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Cheers<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">~Michael<o:p></o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> cfe-dev-bounces@cs.uiuc.edu [mailto:cfe-dev-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>Caitlin Sadowski<br>
<b>Sent:</b> Friday, July 01, 2011 8:58 AM<br>
<b>To:</b> cfe-dev@cs.uiuc.edu; Delesley Hutchins; Jaeheon Yi; Jeffrey Yasskin; cormac@cs.ucsc.edu<br>
<b>Subject:</b> [cfe-dev] Proposal for thread safety attributes for Clang<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The following is a proposal for a project we would like to contribute to Clang. Feel free to discuss.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
Caitlin Sadowski<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Google & University of California at Santa Cruz<o:p></o:p></p>
<div>
<p class="MsoNormal"><span style="font-size:13.5pt"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><b><span style="font-size:14.0pt;font-family:"Arial","sans-serif";color:black">Thread Safety Attributes for Clang</span></b><span style="font-size:13.5pt"><br>
<br>
</span><b><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">Summary</span></b><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">We would like to add a set of thread safety attributes to Clang. These attributes, based on a prior GCC implementation, will allow for checkable documentation of basic locking
 policies in multithreaded programs.  </span><span style="font-size:13.5pt"><br>
<br>
</span><b><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">Background</span></b><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">The synchronization policies in modern multithreaded code may be poorly documented, and incorrectly inferred by new developers. Furthermore, when these policies are improperly
 followed they often lead to bugs which are difficult to reproduce and diagnose. One strategy for avoiding concurrency bugs is formal documentation of these synchronization policies. By writing this documentation using attribute-based annotations, Clang can
 mechanically check <span style="background:white">and warn about issues that could potentially result in race conditions and deadlocks.</span></span><span style="font-size:13.5pt"><br>
<br>
</span><b><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">Example</span></b><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">A code sample which demonstrates two of the proposed annotations is below. In this code sample, variables are protected by locks from the Mutex class. This class has been annotated
 to specify the API used to lock and unlock.</span><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">*
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">GUARDED_BY</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black;background:white"> specifies a particular lock should be held when accessing
 the annotated variable. Violations of this locking policy may lead to data races.
</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black;background:white">*
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">ACQUIRED_AFTER</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black;background:white">
 annotations document the acquisition order between locks that can be held simultaneously by a thread, by specify the locks that need to be acquired before the annotated lock. Violations of this locking policy may lead to deadlocks.</span><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">1</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#880000;background:white">#include</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#008800;background:white">"thread_annotations.h"</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">2
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#880000;background:white">#define
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">GUARDED_BY</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">(</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">x</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">)</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">__attribute__((</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">GUARDED_BY</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">(</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">x</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">)</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">))</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">3</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#880000;background:white">#define
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">ACQUIRED_AFTER</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">(</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">x</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">)</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">__attribute__((</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">ACQUIRED_AFTER</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">(</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">x</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">)</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">))</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">4</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">5</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">Mutex
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">mu1</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">;</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">6</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">Mutex</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> mu2</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">ACQUIRED_AFTER</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">(</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">mu1</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">);</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">7</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">8</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#000088;background:white">int</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> x</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">GUARDED_BY</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">(</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">mu1</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">);</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">9</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#000088;background:white">int</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> a
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006000;background:white">GUARDED_BY</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">(</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">mu2</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">);</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">10</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> </span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">11</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#000088;background:white">void</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> foo</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">()</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white"> 12</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">{</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">13</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">   mu2</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">.</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">Lock</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">();</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">14</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">   mu1</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">.</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">Lock</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">();</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">15</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">   </span><span style="font-size:11.0pt;font-family:"Courier New";color:#000088;background:white">if</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">(</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">x
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">></span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">2</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">)</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">16</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">     a
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">=</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> x
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">+</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">1</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">;</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">17</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">   </span><span style="font-size:11.0pt;font-family:"Courier New";color:#000088;background:white">else</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">18</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">     a
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">=</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> x
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">-</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">1</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">;</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">19</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">   mu1</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">.</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">Unlock</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">();</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">20</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">   mu2</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">.</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">Unlock</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">();</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">21</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">}</span><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black;background:white">Sample compiler output:</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">ex</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">.</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">cc</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">:</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">In</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#000088;background:white">function</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#008800;background:white">'void foo()'</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">:</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">ex</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">.</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">cc</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">:</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">12</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">:</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
 warning</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">:</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#660066;background:white">Lock</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#008800;background:white">'mu1'</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#000088;background:white">is</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> acquired after
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#000088;background:white">lock</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#008800;background:white">'mu2'</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">(</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">acquired at line
</span><span style="font-size:11.0pt;font-family:"Courier New";color:#006666;background:white">14</span><span style="font-size:11.0pt;font-family:"Courier New";color:#666600;background:white">)</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white">
 but </span><span style="font-size:11.0pt;font-family:"Courier New";color:#000088;background:white">is</span><span style="font-size:11.0pt;font-family:"Courier New";color:black;background:white"> annotated otherwise</span><span style="font-size:13.5pt"><br>
<br>
</span><b><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">Previous Work</span></b><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">As mentioned, thread safety annotations have been implemented in GCC. A full list of the annotations and descriptions for them can be found here:</span><span style="font-size:13.5pt"><br>
<br>
<a href="http://gcc.gnu.org/wiki/ThreadSafetyAnnotation"><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:#000099">http://gcc.gnu.org/wiki/ThreadSafetyAnnotation</span></a><br>
<a href="https://docs.google.com/a/google.com/Doc?id=ddqtfwhb_0c49t6zgr"><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:#000099">https://docs.google.com/a/google.com/Doc?id=ddqtfwhb_0c49t6zgr</span></a><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">These annotations have been in active use in Google’s C++ codebase for a couple of years, so there is a large informal case study of their usefulness. The ideas behind many of
 these annotations come originally from a research paper [1].</span><span style="font-size:13.5pt"><br>
<br>
</span><b><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">Plan</span></b><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">We are planning to re-implement the GCC thread safety attributes in Clang. We will submit a series of patches to the cfe-commits mailing list. Our current plan for this serie
 is as follows:</span><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">1) Basic parsing and semantic checking of the attributes which do not take arguments. In other words, checking whether the attribute is applied in the appropriate context (e.g.
 to a field, with no arguments).</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">2) Basic parsing and semantic checking of the attributes which do take arguments, but without parsing or checking the arguments themselves. At this point, we will simply discard
 the tokens making up the arguments. </span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">3) Attribute argument parsing.</span><span style="font-size:13.5pt"><br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">4) Adding the thread safety analysis checks. We will teach the static analysis-based warnings layer to warn for violations of the annotations discussed on the links above.
</span><span style="font-size:13.5pt"><br>
<br>
</span><b><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">Future Projects</span></b><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">Once we have this core set of thread safety annotations implemented, we have several directions for future work we would like to pursue. These include supporting additional types
 of annotations. For example, we would like to extend the system to support annotations for functions which only touch thread-local data and atomic functions which always execute as if they are not interleaved with operations of other threads. We would also
 like to build an annotation inference system; this system would enable application of the thread safety analysis to large amounts of legacy code.</span><span style="font-size:13.5pt"><br>
<br>
</span><span style="font-size:11.0pt;font-family:"Arial","sans-serif";color:black">[1] C. Flanagan and S. N. Freund. Type-based race detection for Java. In Programming Language Design and Implementation (PLDI), June 2000.</span><span style="font-size:13.5pt"><o:p></o:p></span></p>
</div>
</div>
</div>
</body>
</html>