6

I'm aware that goroutines are the way to deal with concurrency in Go, however I'm running a test in which I will be comparing a regular multithreaded server vs a server using level triggered epoll vs edge triggered epoll. I can figure out how to create the epoll ones, however I've searched hi and low on how to create threads manually to no avail.

Jonathan Eustace
  • 2,469
  • 12
  • 31
  • 54
  • 2
    I'm not sure what you're asking for: the Go runtime *explicitly* hides low-level OS threads from you, and only exposes some control over them with the sole purpose of allowing better integration with external C libraries (and syscalls). Attempting to work against it (say, bolting your own low-level OS management onto the Go runtime) is not gonna work because this idea defeats the chief purpose of the Go runtime (with its fine-tuned goroutine scheduling etc). I mean, you would be creating some other runtime, not working with Go. – kostix Feb 06 '15 at 17:56
  • I mean, for instance, you're able to call out into the C code (via `cgo` or otherwise) and do any wild things while there -- including creating new pthreads, using polling etc, -- but not actually executing Go code. So what's the purpose? – kostix Feb 06 '15 at 17:58
  • Maybe it's merely to fulfil his curiosity? The question sounds theoretical. – Martin Gallagher Feb 06 '15 at 18:11
  • Yes it's theoretical. It's actually for an assignment in a software engineering class where we are explicitly testing the difference in performance using standard multithreading, select multiplexing (or level triggered epoll) and edge triggered epoll. The professor has given us the option to chose our own language, thus we all chose a different language to use. I chose Go. – Jonathan Eustace Feb 06 '15 at 18:50
  • 2
    If I understand correctly, the Go runtime uses [edge triggering](https://github.com/golang/go/blob/4ce06f4b5caab3874f30f14551aa3f8e08f2de3e/src/runtime/netpoll_epoll.go#L42). The abstraction provided by the Go runtime over these low-level details may get in the way of this assignment. If I had to do this assignment, I'd do it in Python. All of the low-level details of threads, select, epoll, etc are exposed directly to the application programmer in Python. – Charlie Tumahai Feb 06 '15 at 19:27
  • 1
    @Jthomps -- seconding that Go seems the wrong language here. Since one way to use epoll is built into the runtime, doing it another way is likely to be harder and may not work correctly at all. – twotwotwo Feb 06 '15 at 21:40

2 Answers2

6

You cannot do that. In Go you cannot control this kind of stuff.

Volker
  • 40,468
  • 7
  • 81
  • 87
  • 1
    ...and this is a Very Good Thing in the sense that concurrency is traditionally considered *hard*, because of exposing unnecessary detail. CSP provides a clean abstraction for concurrency, not unlike the way that programming languages provide a clean abstraction over assembly code. – Rick-777 Feb 07 '15 at 17:52
5

You might be able to bind a goroutine to a CPU thread: http://play.golang.org/p/mNPCyvpN2R (run locally on a multi CPU/core machine).

Martin Gallagher
  • 4,444
  • 2
  • 28
  • 26