Golang supports native thread and multi process?

1,029 views
Skip to first unread message

小菜

unread,
Dec 17, 2014, 8:34:31 PM12/17/14
to golan...@googlegroups.com
Golang supports native thread and multi process?
If I don't want to use goroutine.

Ian Lance Taylor

unread,
Dec 17, 2014, 9:43:22 PM12/17/14
to 小菜, golang-nuts
On Wed, Dec 17, 2014 at 5:34 PM, 小菜 <yxw.2...@gmail.com> wrote:
>
> Golang supports native thread and multi process?
> If I don't want to use goroutine.

There is no direct access to native threads in Go.

Go does support multiple processes via the os/exec package.

Ian

小菜

unread,
Dec 17, 2014, 10:18:28 PM12/17/14
to golan...@googlegroups.com
How to  use  pthreads  in golang?



在 2014年12月18日星期四UTC+8上午9时34分31秒,小菜写道:

andrey mirtchovski

unread,
Dec 17, 2014, 10:20:39 PM12/17/14
to 小菜, golang-nuts
> How to use pthreads in golang?

what exactly are you trying to do? why do you think you need pthreads to do it?

小菜

unread,
Dec 17, 2014, 10:52:09 PM12/17/14
to golan...@googlegroups.com

Let goroutine run in the specified CPU core

Get goroutine ID

Let the appointed tasks running on the specified goroutine

Because  I can't do this , it is  not suported!

So  I want to use natvie thread or multi process.




在 2014年12月18日星期四UTC+8上午9时34分31秒,小菜写道:

andrey mirtchovski

unread,
Dec 17, 2014, 10:57:26 PM12/17/14
to 小菜, golang-nuts
> Let goroutine run in the specified CPU core

https://github.com/golang/go/wiki/LockOSThread

> Get goroutine ID

depending on why you want this you can simulate it in any number of
ways. for example, you can assign each goroutine a unique id on
startup. this is independent of the runtime.

> Let the appointed tasks running on the specified goroutine

you can do this by sending the appropriate task to the appropriate
goroutine. function pointers are first class members in Go's type
system. this is a communications problem, not a language problem.

Ian Lance Taylor

unread,
Dec 18, 2014, 12:10:45 AM12/18/14
to 小菜, golang-nuts
On Wed, Dec 17, 2014 at 7:52 PM, 小菜 <yxw.2...@gmail.com> wrote:
>
> Let goroutine run in the specified CPU core
>
> Get goroutine ID
>
> Let the appointed tasks running on the specified goroutine
>
> Because I can't do this , it is not suported!
>
> So I want to use natvie thread or multi process.

I recommend using Go as it is designed to be used.

If you want pthreads, use C or C++.

Ian

Russel Winder

unread,
Dec 18, 2014, 1:26:50 AM12/18/14
to golan...@googlegroups.com

On Wed, 2014-12-17 at 21:10 -0800, Ian Lance Taylor wrote:
>
[…]
> I recommend using Go as it is designed to be used.

Definitely.

> If you want pthreads, use C or C++.

In C++11 and later you do not use pthreads. If you use threads, you
use std::thread. Actually in modern C++ you shouldn't really be
explicitly using threads, you should do things with asynchronous
function calls and futures.

--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder

Reply all
Reply to author
Forward
0 new messages