On Mon, Oct 3, 2016 at 12:24 PM, 'SrimanthG' via golang-nuts
<
golan...@googlegroups.com> wrote:
>
> Do you mean to say that as long as the process is running instructions, it
> will not let any other goroutine use that OS thread and execute?
It's either somewhat simpler or much more complex than that. It is
simpler in the sense that while runtime.LockOSThread is in effect, no
other goroutine will be able to run on that thread. It is more
complex in that this does not in any way imply that no other goroutine
will be able to run. The Go scheduler multiplexes goroutines onto
threads. While runtime.LockOSThread is in effect, the scheduler will
not put any other goroutine on that thread. But it will still happily
run goroutines on other threads.
> If so, can the documentation be updated to mention sleeping as cause for
> letting other goroutines in.
Give the above, i don't think that would be useful.
it sounds like you want to ensure that part of your program executes
by itself, with no other code running in parallel. That is not the
problem that runtime.LockOSThread solves. LockOSThread is for a
completely different problem: ensuring coordination between Go code
and C code, when the C code uses thread-local storage and therefore
expects to always be run on the same thread. To ensure that code
executes by itself, use the facilities in the sync package.
> Also, what other calls can result in other goroutines being used? Would a
> network call waiting for IO result in a goroutine context switch?
Yes. Among many other things.
Ian