Difference between Go's multithreading and pthread or Java Threads

1,631 views
Skip to first unread message

shreyasva

unread,
Feb 22, 2011, 11:32:05 AM2/22/11
to golang-nuts
I read somewhere that Go's multithreading is implemented using
pthreads, is this true.
What is the impetus for using Go's multithreading over other options.
Taken a algorithm that can be parallelised and implemented in Go and
C, which one would run faster.

John Asmuth

unread,
Feb 22, 2011, 11:39:38 AM2/22/11
to golang-nuts

Mike Ramirez

unread,
Feb 22, 2011, 11:47:46 AM2/22/11
to golan...@googlegroups.com

I can't answer this definitively, but have you tried benchmarking these things yourself?

With this said, Go is still not on par with C in terms of performance yet, there is a lot of room for improvement with go.

Mike

--

Charity, n.:

A thing that begins at home and usually stays there.

Alexander Surma

unread,
Feb 22, 2011, 11:56:14 AM2/22/11
to golan...@googlegroups.com
> I read somewhere that Go's multithreading is implemented using
> pthreads, is this true.
This is not entirely true.

Afaik, pthreads are used only, when you compile your Go code with gccgo.
The 8c/6c use an own, much more lightweight version of threads (that's
why they're called go routines) with their own scheduler and cooperative
scheduling(!). You can see this, if you run a go program with multiple
go routines. Your os's process view will only show one process (in
contrast to the same program compiled with gccgo).

Regarding your performance question: This depends heavily on benchmarked
program.
Gccgo is better when it comes to optimizing. However, context switches
of go routines are much cheaper. So big number of short go routines
might be faster in 8c/6c, a few, rather long go routines might be more
efficient with gccgo.

HTH,
Surma

El-Hassan Wanas

unread,
Feb 22, 2011, 2:10:40 PM2/22/11
to golan...@googlegroups.com
IIRC, the number of threads the go runtime will spawn is undefined, but the number of goroutines is greater than or equal to the number of threads. The goroutines are scheduled by each thread that is responsible for them.

Wanas

Paulo Pinto

unread,
Feb 22, 2011, 2:24:00 PM2/22/11
to golang-nuts
Actually how do go routines compare against using fibers in Windows,
or
Solaris LWP?

Or even against multithreading libraries like Java
util.concurrent, .Net TPL,
or C++ TBB and PPL.

--
Paulo

Rob 'Commander' Pike

unread,
Feb 22, 2011, 2:41:24 PM2/22/11
to Paulo Pinto, golang-nuts

On Feb 22, 2011, at 11:24 AM, Paulo Pinto wrote:

> Actually how do go routines compare against using fibers in Windows,
> or
> Solaris LWP?

They're supported by the language. The rest is implementation detail.

-rob


bflm

unread,
Feb 22, 2011, 2:56:48 PM2/22/11
to golang-nuts
On Feb 22, 8:24 pm, Paulo Pinto <paulo.jpi...@gmail.com> wrote:
> Actually how do go routines compare against using fibers in Windows,
> or
> Solaris LWP?
>
> Or even against multithreading libraries like Java
> util.concurrent, .Net TPL,
> or C++ TBB and PPL.

E.g.: "Goroutines are multiplexed as needed onto system threads."
src: http://golang.org/doc/GoCourseDay3.pdf

In other words - a goroutine is not by default fixed to execute only
in the same thread in which it was created. I think this might be the
most important difference when comparing to some of the above
mentioned (eco)systems/libs.
Reply all
Reply to author
Forward
0 new messages