You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
GOHOSTARCH="amd64"
GOHOSTOS="linux"
What did you do?
I am wondering whether the following steps are safe:
in one go routine lock Mutex M, and then pass M's pointer and a golang exported function(with //export functionName above the function) to a cgo function, lock M again. The go routine will be blocked.
after the c library recived the M's pointer and exported function, it starts to do some background job, after the job is completed, it will call the exported function and pass M's pointer as a parameter.
the exported function will unlock the Mutex
the blocked go routine will be unblocked.
You could find the specific code in this patch, if I do not make it clear.
The sync.Mutex is locked in one go routine and uncloked is called in a go exported function which is called by a c library. Will the exported function be scheduled to the original OS thread which owns the blocked go routine? Or is lock/unlock sync.Mutex in different OS thread safe? I know it's safe to lock/unlock sync.Mutex in different go routines, but lock/unlock mutex(OS) in different pthreads is not safe.
The text was updated successfully, but these errors were encountered:
It's fine to lock and unlock a sync.Mutex in different operating system threads. Since goroutines move between threads unpredictably, it would be quite painful to use sync.Mutex if you were required to always access it on the same thread.
Note that we don't use our issue tracker for questions, and it's generally better to ask questions in a forum. You will typically get faster and better answers. See https://golang.org/wiki/Questions.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am wondering whether the following steps are safe:
You could find the specific code in this patch, if I do not make it clear.
The sync.Mutex is locked in one go routine and uncloked is called in a go exported function which is called by a c library. Will the exported function be scheduled to the original OS thread which owns the blocked go routine? Or is lock/unlock sync.Mutex in different OS thread safe? I know it's safe to lock/unlock sync.Mutex in different go routines, but lock/unlock mutex(OS) in different pthreads is not safe.
The text was updated successfully, but these errors were encountered: