/* * Asynchronous DNS host name resolution. This program creates one * ST thread for each host name (specified as command line arguments). * All threads do host name resolution concurrently. */ int main(int argc, char *argv[]) { if (st_init() < 0) { perror("st_init"); exit(1); } condition = st_cond_new(); mutex = st_mutex_new(); int maxQueueP = 15; int maxQueueC = 10; st_thread_t p[6],c[6]; int i = 0; for (; i < maxQueueP; ++i) { if ( (p[i] = st_thread_create(producer,i,1,0) ) == NULL) { perror("st_thread_create producer failed"); exit(1); } } i = 0; for (; i < maxQueueC; ++i) { if ( (c[i] = st_thread_create(consumer,i,1,0) ) == NULL) { perror("st_thread_create consumer failed"); exit(1); } } i = 0; for (; i < maxQueueP; ++i) { st_thread_join(p[i],0); } i = 0; for (; i < maxQueueC; ++i) { st_thread_join(c[i],0); } /* NOTREACHED */ return 1; }
int main() { st_thread_t thread; int rc; int i, j, s; arg = -1; res = -1; st_init(); for(i = 0; i < 10; i++) { s = 0; for(j = 0; j < 10000; j++) { res = -1; arg = j; thread = st_thread_create(thread_routine, NULL, 1, 0); st_sleep(0); while(res < 0) st_sleep(0); s += res; st_thread_join(thread, NULL); arg = -1; } } printf("%d\n", s); return 0; }
void SrsThread::dispose() { if (disposed) { return; } // the interrupt will cause the socket to read/write error, // which will terminate the cycle thread. st_thread_interrupt(tid); // when joinable, wait util quit. if (_joinable) { // wait the thread to exit. int ret = st_thread_join(tid, NULL); if (ret) { srs_warn("core: ignore join thread failed."); } } // wait the thread actually terminated. // sometimes the thread join return -1, for example, // when thread use st_recvfrom, the thread join return -1. // so here, we use a variable to ensure the thread stopped. // @remark even the thread not joinable, we must ensure the thread stopped when stop. while (!really_terminated) { st_usleep(10 * 1000); if (really_terminated) { break; } srs_warn("core: wait thread to actually terminated"); } disposed = true; }
int main(int argc, char *argv[]) { int status; st_init(); status = ares_library_init(ARES_LIB_INIT_ALL); if (status != ARES_SUCCESS) { fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status)); return 1; } st_thread_t t = st_thread_create(do_lookup, (void *)"A", 1, 1024 * 128); st_thread_t t2 = st_thread_create(do_lookup, (void *)"B", 1, 1024 * 128); st_thread_join(t, NULL); st_thread_join(t2, NULL); ares_library_cleanup(); return 0; }
void SrsEncoder::on_unpublish() { if (tid) { loop = false; st_thread_interrupt(tid); st_thread_join(tid, NULL); tid = NULL; } clear_engines(); }
void SrsThread::stop() { if (tid) { loop = false; // the interrupt will cause the socket to read/write error, // which will terminate the cycle thread. st_thread_interrupt(tid); // wait the thread to exit. st_thread_join(tid, NULL); tid = NULL; } }
void SrsThread::stop() { if (tid) { loop = false; // the interrupt will cause the socket to read/write error, // which will terminate the cycle thread. st_thread_interrupt(tid); // wait the thread to exit. int ret = st_thread_join(tid, NULL); // TODO: FIXME: the join maybe failed, should use a variable to ensure thread terminated. if (ret != 0) { srs_warn("join thread failed. code=%d", ret); } tid = NULL; } }