MCPcopy Create free account
hub / github.com/acl-dev/acl / main

Function main

lib_acl/samples/thread/thread_pool1/main.cpp:191–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191int main(int argc acl_unused, char *argv[] acl_unused)
192{
193 acl_pthread_pool_t *thr_pool;
194 int max_threads = 20; /* ��ಢ��20���߳� */
195 int idle_timeout = 10; /* ÿ�������߳̿���10����Զ��˳� */
196 static __thread ACL_VSTRING *buf = NULL;
197
198 if (1) {
199 test_thread_pool();
200 exit (0);
201 }
202
203 buf = acl_vstring_alloc(256);
204 acl_vstring_sprintf(buf, "in main thread, id=%u",
205 (unsigned int) acl_pthread_self());
206 acl_pthread_atexit_add(buf, main_thread_atexit);
207
208
209 thr_pool = thr_pool_create(max_threads, idle_timeout);
210 run_thread_pool(thr_pool);
211
212 if (0) {
213 /* ����������� acl_pthread_pool_destroy�������ڵ������̳߳����ٺ�����
214 * ���̱߳�����֪ͨ�����߳��˳������п����̲߳��صȴ����г�ʱʱ�����˳�,
215 */
216 printf("> wait all threads to be idle and free thread pool\r\n");
217 /* ���������̳߳� */
218 acl_pthread_pool_destroy(thr_pool);
219 } else {
220 /* ��Ϊ���������� acl_pthread_pool_destroy���������п����̶߳��ǵ�����
221 * ��ʱʱ�䵽�����˳�
222 */
223 while (1) {
224 int ret;
225
226 ret = acl_pthread_pool_size(thr_pool);
227 if (ret == 0)
228 break;
229 printf("> current threads in thread pool is: %d\r\n", ret);
230 sleep(1);
231 }
232 /* �̳߳��еĹ����߳���Ϊ0ʱ�����̳߳� */
233 printf("> all worker thread exit now\r\n");
234 acl_pthread_pool_destroy(thr_pool);
235 }
236
237 /* ���̵߳ȴ��û����ն����������ַ����˳� */
238 printf("> enter any key to exit\r\n");
239 getchar();
240
241 return (0);
242}

Callers

nothing calls this directly

Calls 10

acl_vstring_allocFunction · 0.85
acl_vstring_sprintfFunction · 0.85
acl_pthread_selfFunction · 0.85
acl_pthread_atexit_addFunction · 0.85
thr_pool_createFunction · 0.85
run_thread_poolFunction · 0.85
acl_pthread_pool_destroyFunction · 0.85
acl_pthread_pool_sizeFunction · 0.85
test_thread_poolFunction · 0.70
sleepFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…