But note that to use shared memory is invariably the wrong thing to do
-- just because you can do something doesn't mean you should.
Shared-memory multithreading may be a reasonable underlying
infrastructure for realizing parallel systems frameworks, but it is the
wrong model for applications programmers to work with. You should
always use a higher-level model, cf. actor model, CSP, dataflow, data
parallelism. It is worth noting that all programming languages except C
-- i.e. C++, Java, Scala, Erlang, Clojure, Python, and of course Go --
are moving to providing higher-level architecture frameworks over
threading exactly because it is the right thing to do.
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@russel.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Alexander,
On Sun, 2010-05-09 at 11:27 +0200, ⚖ Alexander "Surma" Surma wrote:
> It means that goroutines share their memory and you can therefore pass
> pointers from one goroutine to another without causing a access
> violation.
But note that to use shared memory is invariably the wrong thing to do
-- just because you can do something doesn't mean you should.
Yes and no. Amongst programmers who know what they are doing, and are
thinking as they code, clearly this is an overstatement. However,
sadly, it is all too difficult to overestimate the incompetence of the
average programmer, especially when it comes to issues relating to
concurrency and parallelism.
> * the pointer may refer to an immutable object.
>
Immutable is good, especially in a concurrent and parallel system
context.
>
> * the pointer may be the responsibility of a single goroutine at
> a time
>
Ownership issues tend to be the biggest problems in C, C++, Java, . . .
the question is whether there is only a single owner even in the case
where you think there is.
Definitely not. Erlang has shown that harnessing actor model/CSP is a
good way of structuring single memory space systems (*). Which is (I
infer from the documentation) the inspiration behind goroutines and the
reason they are the way they are.
(*) Whether PGAS, e.g. Chapel, X10, Fortress, ever takes hold is a moot
point.
"by convention usually" presumably means that there is no barrier to
misusing or misunderstanding, leading to serious errors? Again, not a
problem for good programmers, but a potential minefield for average and
poor programmers.
> > Erlang has shown that harnessing actor model/CSP is a
> > good way of structuring single memory space systems (*). Which is (I
> > infer from the documentation) the inspiration behind goroutines and the
> > reason they are the way they are.
>
> The inspiration behind goroutines is the lineage from Limbo to Alef
> to Newsqueak to CSP. Erlang is based on CSP too but was not a
> direct influence (in particular, Erlang doesn't even have the concept
> of a channel!).
Given the reported dates of appearance of the languages I am thinking
your lineage isn't quite right. I am guessing that Newsqueak and Limbo
used ideas from CSP and Alef used ideas from Newsqueak and Limbo. And
thence to Go. However, I am sure Rob can put us right.
occam really needs to appear somewhere at the beginning of that list of
antecedants of Go?
There is an interesting tension here. I think it is well accepted that
good programmers prefer power and flexibility at the cost of safety
support and still get things right (with some errors obviously :-) Weak
and poor programmers though are generally unable to survive with the
same languages, even if they think they are doing. Clearly there is no
one answer to this conundrum, at least not yet.
> There are lots of conventions in Go. The fact that a method with
> the signature Read([]byte) (int, os.Error) reads from an input stream
> is a convention too, with no barrier to misuse or misunderstanding.
> It is incredibly powerful, and at least some of that power comes from
> relying entirely on convention. Go would simply not be usable
> if every type with a Read method had to say "implements io.Reader"
> somewhere in its declaration: it doesn't scale.
Convention over configuration has become a big win in build and
configuration management. Again though with power and flexibility comes
responsibility. Weak and poor staff tend to be unable or unwilling to
face up to the responsibility.
Personally I have no problem aiming for using only the best -- hire 1/3
the number of staff, pay them 3 times as much, and get twice the amount
of work done per unit time. But this only works using flexible,
powerful, expressive languages that are usable.
> As for ownership conventions, there is a growing body of anecdotal
> evidence that programmers can write correct concurrent code in Go
> easily, without the misunderstandings you fear, even programmers
> who have not written parallel code before in other languages.
> (Perhaps they are the best suited to it, since they don't have to
> unlearn the complexity of mutexes and condition variables.)
I am finding that as soon as organizations use actors, CSP, dataflow or
data parallelism instead of shared-memory multithreading (with locks,
mutexes, etc.) as the only acceptable way of developing parallel
applications, many more of the programming staff are able to cope with
concurrency and parallelism. Anecdotal evidence only I'm afraid, but
very indicative of the potentially right way forward.
[ . . . ]
> The lineage is in reverse chronological order.
> I did forget one step: it should be Newsqueak to Squeak to CSP.
>
> > occam really needs to appear somewhere at the beginning of that list of
> > antecedants of Go?
>
> I wasn't there, but my understanding is that Occam and Squeak
> simply share a common ancestor (CSP).
Rob has chipped in here . . .
On Sun, 2010-05-09 at 13:05 -0700, Rob 'Commander' Pike wrote:
> Russ's historical analysis is right, except that there were two CSPs.
> The original 1978 paper did not have channels; the later book did.
> Newsqueak was the first programming language I ever used that had
> channels, but that is not a claim of invention. I honestly have no
> memory of where idea for channels in Newsqueak came from, but I'm
> pretty sure I didn't see the CSP book until afterwards. I do have a
> vivid memory of getting the idea for the implementation of
> hyperthreading in Newsqueak by generalizing something I read in the
> HUB paper by O'Dell, which was based on much earlier work by Masamoto;
> that was the trigger to write the language. Winterbottom grafted
> Newsqueak's communication ideas onto a C-like systems language to
> create Alef. Limbo arrived when it was time to build a virtual
> machine for embedded processing.
Thanks for chipping in these recollections. Most interesting. I think
it would be useful to get some of the "historians of computing" to
collate as many as possible of snippets such as this to add to the
modeling of the history of programming languages from c1950 onwards.
>
> Neither Occam nor Erlang influenced those languages. I didn't learn
> much about Occam until after Newqueak, and about Erlang until after
> Limbo. It was a long time ago but I believe I ignored Occam primarily
> because of its lack of first-class channels; its roots in hardware did
> not enable that generality.
I think that there being parallel independent development of essentially
similar ideas is both useful and indicative that the ideas are likely to
be important. cf. calculus, differential geometry/gauge theories,
virtual machines, channels, etc.
>
> That ignorance was repaid. I don't believe the concurrent programming
> language community knows much about Newsqueak.
I think you are right. Certainly the HPC community don't. They appear
to have a problem seeing beyond MPI and OpenMP.