On Fri, Jul 19, 2013 at 4:47 PM, James Sumners <span dir="ltr">&lt;<a href="mailto:james.sumners@gmail.com" target="_blank">james.sumners@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I&#39;m guessing you are asking which is easier to develop thread safe<br>
applications in. If that&#39;s the case, I&#39;m going to say C is not it.<br>
Evidence -- [1].<br></blockquote><div><br></div><div>Well, the question there was not so great.  This is a thread-safe function</div><div>in C that&#39;s easy to create:</div><div><br></div><div>int add1(int n) { return n + 1; }</div>
<div><br></div><div>The reason it&#39;s thread safe is that there are no side effects.  That&#39;s</div><div>why functional language aficionados brag about their languages being</div><div>easier to use with concurrency.</div>
<div><br></div><div>That questioner was really asking about making critical sections, </div><div>which is not a very good way to do synchronization (as opposed to</div><div>data-based locking or message passing), but the questioner had</div>
<div>that particular thing in mind, and it&#39;s true that the C language itself,</div><div>as of C99, doesn&#39;t help.  (I bet pthreads is the most popular way to</div><div>implement critical sections with C.)</div><div>
<br></div><div>These days many people are taking it to the next level and trying to</div><div>avoid synchronization altogether with &quot;lock free&quot; data structures that</div><div>can be safely modified by concurrently running processes.  They do</div>
<div>that because the number of cores in a computer keeps going up.</div><div><br></div><div>  Paul McKenney</div><div>  Structured Deferral: Synchronization via Procrastination</div><div>  <a href="https://queue.acm.org/detail.cfm?id=2488549">https://queue.acm.org/detail.cfm?id=2488549</a></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
For any hope of &quot;easy&quot; you&#39;d have to switch to C++. Doing that,<br>
though, means spending the time to find the library that works for<br>
you. Hell, Id Software said &quot;eff it&quot; and wrote their own -- [2] (see<br>
[3] for a good review of their model).<br></blockquote><div><br></div><div>One interesting thing about C++ is the multithreading support in the</div><div>new standard</div><div><br></div><div><a href="https://en.wikipedia.org/wiki/C%2B%2B11#Multithreading_memory_model">https://en.wikipedia.org/wiki/C%2B%2B11#Multithreading_memory_model</a></div>
<div></div></div><div><br></div>-- <br>  Ed Cashin &lt;<a href="mailto:ecashin@noserose.net">ecashin@noserose.net</a>&gt;<br>  <a href="http://noserose.net/e/">http://noserose.net/e/</a><br>  <a href="http://www.coraid.com/">http://www.coraid.com/</a>