Linux (C)多執行緒學習(入門)

2021-07-15 15:09:10 字數 1292 閱讀 5404

下面兩個仁兄總結非常好。

總結比較好:

比較具體(例子):

主要學習乙個例子:

/*

* test1.c

* * created on: 2023年7月26日

* author: andy_cong

*//*

* 利用多執行緒與有名管道技術,

* 實現兩個程序之間傳送即時訊息,實現聊天功能。

* */

//mkfifo xx (新建乙個管道xx)

//兩個程式test1 test2 兩個管道fofi1 fofi2

#include#include#include#include#include#include#include #include#include #include #include #include #include void *writefofi(void *arg)

char buf[1024];

while(1)

close(fd);

return null;

}void *readfofi(void *arg)

char buf[1024];

while (1)

close(fd);

return null;

}int main(int argc,char *argv)

/*

* test2.c

* * created on: 2023年7月26日

* author: andy_cong

*/#include#include#include#include#include#include#include #include#include #include #include #include #include void *writefofi(void *arg)

char buf[1024];

while(1)

close(fd);

return null;

}void *readfofi(void *arg)

char buf[1024];

while (1)

close(fd);

return null;

}int main(int argc,char *argv)

執行結果:

linux C 多執行緒

標頭檔案 include 執行緒建立 pthread create 執行緒退出 pthread exit 互斥鎖 pthread mutex init pthread mutex lock pthread mutex unlock void thread function void arg if 0...

Linux C 多執行緒程式設計學習筆記

includedefault 1 thread noexcept initialization 2 template explicit thread fn fn,args args copy deleted 3 thread const thread delete move 4 thread thr...

Linux c 執行緒入門

include include include include include void print msg1 void void print msg2 void void thread create pthread t thread 2 int main void print msg1 int f...