Maxi <
trust...@googlemail.com> writes:
> This makes me wonder what Ian meant when he said that it would all
> work like I initially asked - after all, I specifically said "callback
> from a c thread into Go", and he said it would work. Currently you
> said that it can't work, because the thread has to be a Goroutine, so
> I wouldn't call that a c thread anymore..
A goroutine is not the same as a thread, but when a goroutine calls into
C code it is running in a thread. From the perspective of the C code,
it is a thread. That thread can call back to Go code. Other threads,
those created directly by the C code, currently can not.
It's actually a bug that other threads can not call Go code. There have
been a couple of efforts toward fixing this, but none have completed.
> it uses a lot of pthread specific stuff, like
> pthread_setspecific() to set thread local variables
There is no problem with having a goroutine call C code that uses
pthread_setspecific. The C code will be running in a specific thread.
However, if you want Go code to call C code that calls
pthread_setspecific, and then have the C code return back to the Go
code, and then have the Go code call C code, and have that C code use
pthread_getspecific, then you must use runtime.LockOSThread in the Go
code so that the C code always sees the same thread.
Ian