日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux的基础知识——线程

發布時間:2024/7/19 linux 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux的基础知识——线程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

        • 1.什么是線程?
        • 2.linux內核線程實現原理
        • 3.線程共享資源
        • 4.線程的非共享資源
        • 5.線程優缺點
        • 6.線程的控制原語
          • 6.1 pthread_self函數
          • 6.2 pthread_create函數
          • 6.3 程序:創建線程
        • 7.線程與共享
        • 8.pthread_exit線程退出函數

1.什么是線程?

2.linux內核線程實現原理

3.線程共享資源

4.線程的非共享資源

5.線程優缺點

6.線程的控制原語

6.1 pthread_self函數

6.2 pthread_create函數

6.3 程序:創建線程
#include<stdio.h> #include<pthread.h> #include<stdlib.h> #include<unistd.h>void *thrd_func(void *arg) {printf("子進程ID:%u;子線程ID:%lu\n",getpid(),pthread_self()); } int main() {pthread_t tid;int ret;printf("主進程ID:%u;主線程ID:%lu\n",getpid(),pthread_self());ret = pthread_create(&tid,NULL,thrd_func,NULL);if(ret != 0){printf("pthread_create error\n");exit(1);}sleep(1);return 0; }

7.線程與共享

8.pthread_exit線程退出函數

#include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<pthread.h>void *tfn(void *arg) {int i;i = (int)arg;printf("i am %dth thread,thread_id:%lu\n",i+1,pthread_self());return NULL; }int main() {int n=5,i;pthread_t tid;for(i=0;i<n;i++){pthread_create(&tid,NULL,tfn,(void *)i);}printf("i am main thread,thread id:%lu\n",pthread_self());pthread_exit(NULL); }

總結

以上是生活随笔為你收集整理的linux的基础知识——线程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。