《Go语言编程》[4.4 并发通信]代码thread.c和thread.go错误

《Go语言编程》[4.4 并发通信]代码thread.c和thread.go错误

thread.c程序pthread_create函数第三个参数为线程函数的起始地址,文中并无add函数,源代码如下:

《Go语言编程》[4.4 并发通信]代码thread.c和thread.go错误

thread.c编译时会报未声明错误:

《Go语言编程》[4.4 并发通信]代码thread.c和thread.go错误

根据语境推测应该是count,替换如下:

《Go语言编程》[4.4 并发通信]代码thread.c和thread.go错误

重新编译,gcc编译时在最后加参数-lpthread,否则编译报对

pthread_create和pthread_join未定义的引用如下:

《Go语言编程》[4.4 并发通信]代码thread.c和thread.go错误

应当是行末最后加入-lpthread编译,正确编译命令:

gcc -lpthread thread.c -o main

thread.go程序无z变量,应当是counter:

《Go语言编程》[4.4 并发通信]代码thread.c和thread.go错误