代码拉取完成,页面将自动刷新
/*
* WHAT THIS EXAMPLE DOES
*
* We create a pool of 4 threads and then add 40 tasks to the pool(20 task1
* functions and 20 task2 functions). task1 and task2 simply print which thread is running them.
*
* As soon as we add the tasks to the pool, the threads will run them. It can happen that
* you see a single thread running all the tasks (highly unlikely). It is up the OS to
* decide which thread will run what. So it is not an error of the thread pool but rather
* a decision of the OS.
*
* */
#include <stdio.h>
#include <pthread.h>
#include <stdint.h>
#include "thpool.h"
void task(void *arg){
printf("Thread #%u working on %d\n", (int)pthread_self(), (int) arg);
}
int main(){
puts("Making threadpool with 4 threads");
threadpool thpool = thpool_init(4);
puts("Adding 40 tasks to threadpool");
int i;
for (i=0; i<40; i++){
thpool_add_work(thpool, task, (void*)(uintptr_t)i);
};
thpool_wait(thpool);
puts("Killing threadpool");
thpool_destroy(thpool);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。