[ale] Thread safe coding, Java or C

Dustin Strickland dustin.h.strickland at gmail.com
Sat Jul 20 00:05:12 EDT 2013


Ew, Java... How about Python? It's almost as effecient as C code, and has a
decent built-in library for threads. C has very few threading
libraries(assuming you want a multi-platform solution) that I know of. Off
the top of my head, I can think of SDL's thread support, though that's
hardly extensive. If you can stand to code in C++(the wild syntax
deviations make me cringe, personally), there are plenty of threading
libraries available. So many, in fact, that it might be hard to find the
jeans that fit the best, so to speak.

One interesting thing about C++ is the multithreading support in the
> new standard
>

That's something that bothers me about the C++11 standard... It's still
relatively new, and I don't trust that all compilers are going to produce
the same code for something like threads so early on, especially
Microsoft's compilers. Last time I checked, IE still wasn't HTML compliant.
I might feel better about it in a year or two, when I can be sure that
releasing my code using C++'s built-in threads won't break something for a
user/other dev who tries to build in another compiler.


On Fri, Jul 19, 2013 at 11:42 PM, Ed Cashin <ecashin at noserose.net> wrote:

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


More information about the Ale mailing list