Linux多執行緒程式設計初體驗

2021-07-22 21:20:40 字數 765 閱讀 6353

直接上**

#include "pthread.h"    //執行緒庫,執行緒不是通過核心實現的

#include "stdio.h"

#include "stdlib.h"

#include "unistd.h"

void* thread_func(void *arg)

}int main()

sleep(1); //等待1

s,否則程序先結束那麼執行緒就無法執行了

printf("main thread!\n");

return

0;}

寫好**之後使用編譯命令 gcc -o pthread pthread.c會出現如下錯誤:

/tmp/cccbslrq.o:在函式『main』中:

pthread.c:(.text+0x66):對『pthread_create』未定義的引用

collect2: error: ld returned 1 exit status

這是由於pthread庫不是linux的標準庫,需給編譯器指定連線的庫,使用gcc -o pthread pthread.c -lpthread命令,編譯器會尋找libpthread.a靜態庫檔案,並且連線到使用者**。

編譯好之後執行的結果如下:

hi!i'm a thread!

argument set:100

main thread!

iPhone多執行緒程式設計初體驗

from 找了很長時間iphone下多執行緒的程式設計的內容,用到的類是uikit的中nsthread.在google過程中,發現很多文都驚喜地標題著類似 多執行緒的ios4來了 這些想正向引導一下,ios4的亮點在於多工,乙個任務為乙個程序,也叫多程序,而多執行緒在早期的iphoneos上都是有的...

多執行緒 future模式初體驗

第一次使用多執行緒,雖然理解的不是很透徹,但是也值得記錄下。用的是future模式。建立個執行緒池 private executorservice cachedthreadpool executors.newfixedthreadpool 200,new siyuethreadfactory tes...

python 執行緒初體驗

import threading import time class mythread threading.thread def init self,threadid,name,counter threading.thread.init self self.threadid threadid sel...