void ztst_thrctl(){ int i = 0; zthr_id_t id; zthr_t attr; sprintf(attr.name, "thr[0]"); ZDBG("testing ztst_thrctl()..."); zthread_create(&id, zproc_thr1, (void*)&attr); // main loop for(i=0; i< 10; i++){ ZDBG("main loop %d...", i); zsleepms(500); } // cancel thread zthread_cancel(&id); zthread_join(&id); }
int main(int argc, char* argv[]){ Fix_Initialize(); g_apex_cfg = apex_cfg_new(argc,argv); assert(g_apex_cfg); if(g_apex_cfg->log_path){ zlog_use_file(g_apex_cfg->log_path); } else { zlog_use_stdout(); } g_zmq_context = zctx_new(1); g_mutex_hash = zmutex_new(); g_msgid2reply = hash_new(&g_hctrl_msgid2reply, NULL); char* broker = zstrdup(g_apex_cfg->broker); int thread_count = g_apex_cfg->worker_threads; zthread_t* reply_threads = (zthread_t*)zmalloc(thread_count*sizeof(zthread_t)); zthread_t* recv_threads = (zthread_t*)zmalloc(thread_count*sizeof(zthread_t)); for(int i=0; i<g_apex_cfg->worker_threads; i++){ //reply_threads[i] = zthread_new(thread_reply, zstrdup(broker)); recv_threads[i] = zthread_new(thread_recv, zstrdup(broker)); } zfree(broker); for(int i=0; i<thread_count; i++){ //zthread_join(reply_threads[i]); zthread_join(recv_threads[i]); } zmutex_destroy(&g_mutex_hash); hash_destroy(&g_msgid2reply); apex_cfg_destroy(&g_apex_cfg); zctx_destroy(&g_zmq_context); Fix_Uninitialize(); return 0; }