On Fri, Oct 13, 2017 at 12:23 PM, 'Pushkar' via golang-nuts
<golang-nuts@googlegroups.com> wrote:
> 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?

Yes.

> 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.

Yes.

Ian

> 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.

-- 
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