正在显示
1 个修改的文件
包含
57 行增加
和
0 行删除
src/server/spserver/testthreadpool.cpp
0 → 100644
1 | +/* | ||
2 | + * Copyright 2007 Stephen Liu | ||
3 | + * For license terms, see the file COPYING along with this library. | ||
4 | + */ | ||
5 | + | ||
6 | +#include <stdio.h> | ||
7 | +#include <stdlib.h> | ||
8 | +#include <errno.h> | ||
9 | +#include <stdarg.h> | ||
10 | + | ||
11 | +#include "spthread.hpp" | ||
12 | + | ||
13 | +#include "spporting.hpp" | ||
14 | + | ||
15 | +#include "spthreadpool.hpp" | ||
16 | + | ||
17 | +extern int errno; | ||
18 | + | ||
19 | +void threadFunc( void *arg ) | ||
20 | +{ | ||
21 | + int seconds = (int) arg; | ||
22 | + | ||
23 | + fprintf( stdout, " in threadFunc %d\n", seconds ); | ||
24 | + fprintf( stdout, " thread#%ld\n", sp_thread_self() ); | ||
25 | + sleep( seconds ); | ||
26 | + fprintf( stdout, " done threadFunc %d\n", seconds); | ||
27 | +} | ||
28 | + | ||
29 | +int main( int argc, char ** argv ) | ||
30 | +{ | ||
31 | + SP_ThreadPool pool( 2 ); | ||
32 | + | ||
33 | + fprintf( stdout, "**main** dispatch 3\n" ); | ||
34 | + pool.dispatch( threadFunc, (void*)3 ); | ||
35 | + fprintf( stdout, "**main** dispatch 6\n"); | ||
36 | + pool.dispatch( threadFunc, (void*)6 ); | ||
37 | + fprintf( stdout, "**main** dispatch 7\n"); | ||
38 | + pool.dispatch( threadFunc, (void*)7 ); | ||
39 | + | ||
40 | + fprintf( stdout, "**main** done first\n" ); | ||
41 | + sleep( 20 ); | ||
42 | + fprintf( stdout, "\n\n" ); | ||
43 | + | ||
44 | + fprintf( stdout, "**main** dispatch 3\n" ); | ||
45 | + pool.dispatch( threadFunc, (void *) 3 ); | ||
46 | + fprintf( stdout, "**main** dispatch 6\n" ); | ||
47 | + pool.dispatch( threadFunc, (void *) 6 ); | ||
48 | + fprintf( stdout, "**main** dispatch 7\n"); | ||
49 | + pool.dispatch( threadFunc, (void *) 7 ); | ||
50 | + | ||
51 | + fprintf( stdout, "**main done second\n" ); | ||
52 | + | ||
53 | + sleep(20); | ||
54 | + | ||
55 | + return 0; | ||
56 | +} | ||
57 | + |
请
注册
或
登录
后发表评论