News for hackers. Stuff that matters.
Re:Multithreading Magic - Why Everything You Thought You Kne... by po on Sunday February 06, 2011 @07:44AM (#2185509)
I like ZeroMQ but this slideshare doesn't deliver any substance at all. For an overview, skip it and check out the white paper (if you can call it that) cowritten by the same guy (Pieter Hintjens) instead:

http://www.zeromq.org/whitepapers:multithreading-magic

Re:Multithreading Magic - Why Everything You Thought You Kne... by tbrownaw on Sunday February 06, 2011 @11:14AM (#2185810)
The most widely used languages, C and C++, do not offer any support for concurrency. Programmers roll their own by using threading APIs. Languages that do support concurrency, such as Java, Python, .NET, and Ruby, do it in a brute-force manner. Depending on the implementation - there are over a dozen Ruby interpreters, for example - they may offer "green threading" or true multithreading. Neither approach scales, due to reliance on locks. It is left to exotic languages like Erlang to do it right.

You know how I wrote my first concurrent programs? Create threads with pthread_create(3), and pass ownership of objects by sending pointers over connections created with pipe(3). Which sounds an awful lot like this cure-all actor model (which I hadn't heard of yet) that requires languages almost nobody's ever heard of.

Of all the approaches taken to multithreading, only one is known to work properly. That means, it scales to any number of cores, ...

clone(2) and socket(7)

... avoids all locks,...

Your threads/actors still block waiting for messages. I've seen an example of someone using this to write a mutex in Erlang.

... costs little more than conventional single-threaded programming,...

Probably depends how much you have to twist your code to fit this functional+actor model.

... is easy to learn,...

If you discount having to learn a whole new language and turn your code inside-out.

... and does not crash in strange ways.

Instead of crashing, it hangs because you accidentally wrote a mutex.

Re:Multithreading Magic - Why Everything You Thought You Kne... by KirinDave on Sunday February 06, 2011 @06:06PM (#2186735)
> Your threads/actors still block waiting for messages. I've seen an example of someone using this to write a mutex in Erlang.

This statement suggests to me that you've got some fundamental misunderstandings about the nature of actor based programming. Your actor may block on its message queue (and an infinite computation would mean you'd never consult the queue again), but during a message wait it doesn't necessarily block a thread. That's sort of the point of a good Actor model implementation.

If you write a series of symmetric calls that create a dependency, then yes, you will deadlock; the Actor model can't work its magic when you explicitly model blocking calls.

Perhaps you don't know this, but every lock&block system has an equivalently performant Actor-based system, and vice-versa. (See: http://www.sics.se/~adam/pt/duality78.pdf) What this means, for programmers, is that whichever model fits our current problem best is the one to use. We can make either one performant.

P.S., Just because you haven't heard of these languages doesn't mean they are not widely used. What does your personal experience have to do with the viability of a technique?

Re:Multithreading Magic - Why Everything You Thought You Kne... by tbrownaw on Sunday February 06, 2011 @08:18PM (#2187080)
> Your actor may block on its message queue (and an infinite computation would mean you'd never consult the queue again), but during a message wait it doesn't necessarily block a thread. That's sort of the point of a good Actor model implementation.

A thread can block on a syscall or a "while(true);", but won't necessarily idle one of your CPU cores. That's likewise the point of a good task scheduler.

Actors are threads, just they tend to be implemented in userland rather than as OS threads.

> Perhaps you don't know this, but every lock&block system has an equivalently performant Actor-based system, and vice-versa.

Knowing that they're equivalent (up to "frictionless surface" assumptions for performance, ignoring what primitives the hardware provides) is a significant part of why I don't take claims of the actor model's magicalness seriously.

> P.S., Just because you haven't heard of these languages doesn't mean they are not widely used. What does your personal experience have to do with the viability of a technique?

I have heard of them, always in terms of "this is awesome, what's wrong with people that almost nobody actually uses it?".

Re:Multithreading Magic - Why Everything You Thought You Kne... by toddh on Sunday February 06, 2011 @12:02PM (#2185935)
I've built quite a few actor systems in C++ for real-time platforms. You use a threading library like pthreads, which works fine in C++, use thread safe libraries, create an Actor object with a queue that encapsulates a thread, and then have your async messaging system route and drop messages in the right actor queue. As long as application writers can manage their impulses to share state between the threads it works excellently. The only problem is usually the shared state inherent in the memory allocator, so some sort of thread based memory allocation scheme works best. You also get to choose your response latency via priority, which is something you don't get with Erlang.
Re:Multithreading Magic - Why Everything You Thought You Kne... by defen on Sunday February 06, 2011 @12:52PM (#2186032)
Keep in mind that the original point of erlang was "reliable software", not "high performance" (quotes because those are fuzzy terms) - there are many classes of errors that simply cannot happen in erlang that happen all the time in real-world C++ programming. You also get distributed computation for free via a well-tested VM.
Re:Multithreading Magic - Why Everything You Thought You Kne... by toddh on Sunday February 06, 2011 @03:08PM (#2186326)
No doubt, I just wanted to point out that C++ does support concurrency and in some use cases can even be superior.
Re:Multithreading Magic - Why Everything You Thought You Kne... by nikster on Sunday February 06, 2011 @10:29AM (#2185732)
Dunno, made perfect sense to me. It's just that many (most?) programmers, in my own experience, don't fully appreciate the insanity that is traditional "shared data" concurrency.

What I see is that they program something buggy, but where the bugs are rare enough to make the program work most times.

Re:Multithreading Magic - Why Everything You Thought You Kne... by jshen on Sunday February 06, 2011 @11:40AM (#2185874)
For many types of problems, shared state concurrency is not the nightmare it's often made out to be. For example, if your problem can fit into the consumer producer model then it's really easy to make that work on the jvm today.
Re:Multithreading Magic - Why Everything You Thought You Kne... by thijsterlouw on Sunday February 06, 2011 @09:36AM (#2185651)
These slides were part of a "lightning talk" on ZeroMQ (video here: http://streaming.fosdem.org:8000/ferrer/0mq.ogv ). So I think Pieter just wanted to make the audience curious and not dive into the details. I do agree that it might be better to use more slides for patterns and use cases and fewer generic/actor-slides. Also the argument that it's not taught in university was a bit weak.
Re:Multithreading Magic - Why Everything You Thought You Kne... by phintjens on Sunday February 06, 2011 @01:11PM (#2186071)
There's a copy of the video here: http://www.youtube.com/watch?v=CCBYzKfmQ4U

The FOSDEM streaming server seems to be timing out right now.