⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testthreadpool.cpp

📁 同时支持windows和Linux的线程池代码
💻 CPP
字号:
/** * threadpool_test.c, copyright 2001 Steve Gribble * * Just a regression test for the threadpool code. */#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <stdarg.h>#include "threadpool.h"#include "spthread.h"extern int errno;void mylog( FILE * fp, const  char  *format,  /*args*/ ...){	va_list ltVaList;	va_start( ltVaList, format );	vprintf( format, ltVaList );	va_end( ltVaList );	fflush( stdout );}void dispatch_threadpool_to_me(void *arg) {  int seconds = (int) arg;  fprintf(stdout, "  in dispatch_threadpool %d\n", seconds);  fprintf(stdout, "  thread#%ld\n", sp_thread_self() );  sp_sleep(seconds);  fprintf(stdout, "  done dispatch_threadpool %d\n", seconds);}int main(int argc, char **argv) {  threadpool tp;  tp = create_threadpool(2);  fprintf(stdout, "**main** dispatch_threadpool 3\n");  dispatch_threadpool(tp, dispatch_threadpool_to_me, (void *) 3);  fprintf(stdout, "**main** dispatch_threadpool 6\n");  dispatch_threadpool(tp, dispatch_threadpool_to_me, (void *) 6);  fprintf(stdout, "**main** dispatch_threadpool 7\n");  dispatch_threadpool(tp, dispatch_threadpool_to_me, (void *) 7);  fprintf(stdout, "**main** done first\n");  sp_sleep(20);  fprintf(stdout, "\n\n");  fprintf(stdout, "**main** dispatch_threadpool 3\n");  dispatch_threadpool(tp, dispatch_threadpool_to_me, (void *) 3);  fprintf(stdout, "**main** dispatch_threadpool 6\n");  dispatch_threadpool(tp, dispatch_threadpool_to_me, (void *) 6);  fprintf(stdout, "**main** dispatch_threadpool 7\n");  dispatch_threadpool(tp, dispatch_threadpool_to_me, (void *) 7);  fprintf(stdout, "**main done second\n");  destroy_threadpool( tp );  //sp_sleep(20);  return -1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -