I need to call some C functions from Go. I think I know how to proceed 
using cgo.
However, I was wondering how goroutines and blocking calls in the C 
functions work together.
So in the below example (pseudocode) will the goroutine be suspended when 
the pthread_lock call is waiting to acquire the lock?

I am guessing that the Go engine will detect that the OS thread on which 
the goroutine(s) are running is blocked so it will suspend them too.
Once the thread is runnable, the blocked goroutines will be scheduled to 
run.

For example:

int cfunc (int a) {
  pthread_lock(..);
  ++a;
  pthread_unlock();
}

func main() {
  for (i  := 0; i < 100; i++) {
    go cfunc(i)
  }
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to