int main(int argc, char** argv) { int rc; opal_thread_t thr1; opal_thread_t thr2; test_init("opal_thread_t"); OBJ_CONSTRUCT(&thr1, opal_thread_t); OBJ_CONSTRUCT(&thr2, opal_thread_t); thr1.t_run = thr1_run; thr2.t_run = thr2_run; rc = opal_thread_start(&thr1); test_verify_int(OPAL_SUCCESS, rc); rc = opal_thread_start(&thr2); test_verify_int(OPAL_SUCCESS, rc); rc = opal_thread_join(&thr1, NULL); test_verify_int(OPAL_SUCCESS, rc); rc = opal_thread_join(&thr2, NULL); test_verify_int(OPAL_SUCCESS, rc); test_verify_int(3, count); return test_finalize(); }
static void component_shutdown(void) { int i; opal_list_item_t *item; opal_output_verbose(2, orte_oob_base_framework.framework_output, "%s TCP SHUTDOWN", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)); if (ORTE_PROC_IS_HNP && mca_oob_tcp_component.listen_thread_active) { mca_oob_tcp_component.listen_thread_active = false; /* tell the thread to exit */ write(mca_oob_tcp_component.stop_thread[1], &i, sizeof(int)); opal_thread_join(&mca_oob_tcp_component.listen_thread, NULL); } while (NULL != (item = opal_list_remove_first(&mca_oob_tcp_component.listeners))) { OBJ_RELEASE(item); } /* shutdown the module */ if (NULL != mca_oob_tcp_module.api.finalize) { mca_oob_tcp_module.api.finalize(); } }
int main(int argc, char** argv) { int rc; opal_thread_t* thr1; opal_thread_t* thr2; test_init("opal_condition_t"); rc = opal_init(&argc, &argv); test_verify_int(OPAL_SUCCESS, rc); if (OPAL_SUCCESS != rc) { test_finalize(); exit(1); } opal_set_using_threads(true); OBJ_CONSTRUCT(&mutex, opal_mutex_t); OBJ_CONSTRUCT(&thr1_cond, opal_condition_t); OBJ_CONSTRUCT(&thr2_cond, opal_condition_t); thr1 = OBJ_NEW(opal_thread_t); thr2 = OBJ_NEW(opal_thread_t); thr1->t_run = thr1_run; thr2->t_run = thr2_run; rc = opal_thread_start(thr1); test_verify_int(OPAL_SUCCESS, rc); rc = opal_thread_start(thr2); test_verify_int(OPAL_SUCCESS, rc); rc = opal_thread_join(thr1, NULL); test_verify_int(OPAL_SUCCESS, rc); test_verify_int(TEST_COUNT, thr1_count); rc = opal_thread_join(thr2, NULL); test_verify_int(OPAL_SUCCESS, rc); test_verify_int(TEST_COUNT, thr2_count); opal_finalize(); return test_finalize(); }
int opal_cr_finalize(void) { int exit_status = OPAL_SUCCESS; if( --opal_cr_initalized != 0 ) { if( opal_cr_initalized < 0 ) { return OPAL_ERROR; } return OPAL_SUCCESS; } if( !opal_cr_is_tool ) { #if OPAL_ENABLE_FT_THREAD == 1 if( opal_cr_thread_use_if_avail ) { void *data; /* * Stop the thread */ opal_cr_thread_is_done = true; opal_cr_thread_is_active = false; opal_cr_thread_in_library = true; opal_thread_join(&opal_cr_thread, &data); OBJ_DESTRUCT(&opal_cr_thread); OBJ_DESTRUCT(&opal_cr_thread_lock); } #endif /* OPAL_ENABLE_FT_THREAD == 1 */ /* Nothing to do for just process notifications */ opal_cr_checkpointing_state = OPAL_CR_STATUS_TERM; opal_cr_checkpoint_request = OPAL_CR_STATUS_TERM; } #if OPAL_ENABLE_CRDEBUG == 1 if( NULL != opal_cr_debug_free_threads ) { free( opal_cr_debug_free_threads ); opal_cr_debug_free_threads = NULL; } opal_cr_debug_num_free_threads = 0; #endif if (NULL != opal_cr_pipe_dir) { free(opal_cr_pipe_dir); opal_cr_pipe_dir = NULL; } #if OPAL_ENABLE_FT_CR == 1 /* * Close the checkpoint / restart service components */ (void) mca_base_framework_close(&opal_crs_base_framework); #endif return exit_status; }
int opal_progress_thread_finalize(const char *name) { assert(NULL == name); agent_thread_time_to_exit = true; /* break the event loop - this will cause the loop to exit upon completion of any current event */ opal_event_base_loopbreak(agent_evbase); opal_thread_join(&agent_thread, NULL); return OPAL_SUCCESS; }
/* * Module cleanup. */ static void tcp_fini(void) { uint64_t ui64; char *nptr; mca_oob_tcp_peer_t *peer; /* cleanup all peers */ if (OPAL_SUCCESS == opal_hash_table_get_first_key_uint64(&mca_oob_tcp_module.peers, &ui64, (void**)&peer, (void**)&nptr)) { opal_output_verbose(2, orte_oob_base_framework.framework_output, "%s RELEASING PEER OBJ %s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), (NULL == peer) ? "NULL" : ORTE_NAME_PRINT(&peer->name)); if (NULL != peer) { OBJ_RELEASE(peer); } while (OPAL_SUCCESS == opal_hash_table_get_next_key_uint64(&mca_oob_tcp_module.peers, &ui64, (void**)&peer, nptr, (void**)&nptr)) { opal_output_verbose(2, orte_oob_base_framework.framework_output, "%s RELEASING PEER OBJ %s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), (NULL == peer) ? "NULL" : ORTE_NAME_PRINT(&peer->name)); if (NULL != peer) { OBJ_RELEASE(peer); } } } OBJ_DESTRUCT(&mca_oob_tcp_module.peers); if (mca_oob_tcp_module.ev_active) { /* if we used an independent progress thread at * the module level, stop it now */ opal_output_verbose(2, orte_oob_base_framework.framework_output, "%s STOPPING TCP PROGRESS THREAD", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)); /* stop the progress thread */ mca_oob_tcp_module.ev_active = false; /* break the event loop */ opal_event_base_loopexit(mca_oob_tcp_module.ev_base); /* wait for thread to exit */ opal_thread_join(&mca_oob_tcp_module.progress_thread, NULL); OBJ_DESTRUCT(&mca_oob_tcp_module.progress_thread); /* release the event base */ opal_event_base_free(mca_oob_tcp_module.ev_base); } }
void mca_io_base_request_progress_fini(void) { #if OMPI_ENABLE_PROGRESS_THREADS void *ret; /* make the helper thread die */ thread_done = true; if (thread_running) { opal_condition_signal(&progress_cond); opal_thread_join(&progress_thread, &ret); } /* clean up */ OBJ_DESTRUCT(&progress_thread); OBJ_DESTRUCT(&progress_cond); OBJ_DESTRUCT(&progress_mutex); #endif /* OMPI_ENABLE_PROGRESS_THREADS */ }
void orte_rmcast_base_stop_threads(void) { opal_buffer_t *msg=NULL; OPAL_OUTPUT_VERBOSE((5, orte_rmcast_base.rmcast_output, "%s rmcast:base: stopping recv processing thread", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME))); ORTE_ACQUIRE_THREAD(&orte_rmcast_base.recv_process_ctl); if (orte_rmcast_base.recv_process_ctl.running) { ORTE_RELEASE_THREAD(&orte_rmcast_base.recv_process_ctl); opal_fd_write(orte_rmcast_base.recv_pipe[1], sizeof(opal_buffer_t*), &msg); opal_thread_join(&orte_rmcast_base.recv_process, NULL); ORTE_ACQUIRE_THREAD(&orte_rmcast_base.recv_process_ctl); } ORTE_RELEASE_THREAD(&orte_rmcast_base.recv_process_ctl); OPAL_OUTPUT_VERBOSE((5, orte_rmcast_base.rmcast_output, "%s rmcast:base: all threads stopped", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME))); }
static void tool_finalize(void) { if (signals_set) { /* Release all local signal handlers */ opal_event_del(&epipe_handler); opal_event_del(&term_handler); opal_event_del(&int_handler); opal_event_signal_del(&sigusr1_handler); opal_event_signal_del(&sigusr2_handler); } (void) mca_base_framework_close(&orte_errmgr_base_framework); (void) mca_base_framework_close(&orte_routed_base_framework); orte_wait_finalize(); if (progress_thread_running) { /* we had to leave the progress thread running until * we closed the routed framework as that closure * sends a "sync" message to the local daemon. it * is now safe to stop the progress thread */ orte_event_base_active = false; /* break the event loop */ opal_event_base_loopbreak(orte_event_base); /* wait for thread to exit */ opal_thread_join(&progress_thread, NULL); OBJ_DESTRUCT(&progress_thread); progress_thread_running = false; } (void) mca_base_framework_close(&orte_rml_base_framework); (void) mca_base_framework_close(&orte_oob_base_framework); (void) mca_base_framework_close(&orte_state_base_framework); (void) mca_base_framework_close(&orcm_db_base_framework); (void) mca_base_framework_close(&opal_dstore_base_framework); }
int ompi_osc_rdma_module_free(ompi_win_t *win) { int ret = OMPI_SUCCESS; int tmp, i; ompi_osc_rdma_module_t *module = GET_MODULE(win); opal_output_verbose(1, ompi_osc_base_output, "rdma component destroying window with id %d", ompi_comm_get_cid(module->m_comm)); /* finish with a barrier */ if (ompi_group_size(win->w_group) > 1) { ret = module->m_comm->c_coll.coll_barrier(module->m_comm, module->m_comm->c_coll.coll_barrier_module); } /* remove from component information */ OPAL_THREAD_LOCK(&mca_osc_rdma_component.c_lock); tmp = opal_hash_table_remove_value_uint32(&mca_osc_rdma_component.c_modules, ompi_comm_get_cid(module->m_comm)); /* only take the output of hast_table_remove if there wasn't already an error */ ret = (ret != OMPI_SUCCESS) ? ret : tmp; if (0 == opal_hash_table_get_size(&mca_osc_rdma_component.c_modules)) { #if OPAL_ENABLE_PROGRESS_THREADS void *foo; mca_osc_rdma_component.c_thread_run = false; opal_condition_broadcast(&ompi_request_cond); opal_thread_join(&mca_osc_rdma_component.c_thread, &foo); #else opal_progress_unregister(ompi_osc_rdma_component_progress); #endif } OPAL_THREAD_UNLOCK(&mca_osc_rdma_component.c_lock); win->w_osc_module = NULL; OBJ_DESTRUCT(&module->m_unlocks_pending); OBJ_DESTRUCT(&module->m_locks_pending); OBJ_DESTRUCT(&module->m_queued_sendreqs); OBJ_DESTRUCT(&module->m_copy_pending_sendreqs); OBJ_DESTRUCT(&module->m_pending_sendreqs); OBJ_DESTRUCT(&module->m_acc_lock); OBJ_DESTRUCT(&module->m_cond); OBJ_DESTRUCT(&module->m_lock); if (NULL != module->m_sc_remote_ranks) { free(module->m_sc_remote_ranks); } if (NULL != module->m_sc_remote_active_ranks) { free(module->m_sc_remote_active_ranks); } if (NULL != module->m_pending_buffers) { free(module->m_pending_buffers); } if (NULL != module->m_fence_coll_counts) { free(module->m_fence_coll_counts); } if (NULL != module->m_copy_num_pending_sendreqs) { free(module->m_copy_num_pending_sendreqs); } if (NULL != module->m_num_pending_sendreqs) { free(module->m_num_pending_sendreqs); } if (NULL != module->m_peer_info) { for (i = 0 ; i < ompi_comm_size(module->m_comm) ; ++i) { ompi_osc_rdma_peer_info_free(&module->m_peer_info[i]); } free(module->m_peer_info); } if (NULL != module->m_comm) ompi_comm_free(&module->m_comm); if (NULL != module) free(module); return ret; }
int main(int argc, char **argv) { char byte='a'; struct timespec tp= {0, 100}; int count=0; foo_caddy_t *foo; /* Initialize the event library */ opal_init(&argc, &argv); /* setup for threads */ opal_event_use_threads(); /* create a new base */ my_base = orte_event_base_create(); /* launch a progress thread on that base*/ pipe(progress_thread_pipe); OBJ_CONSTRUCT(&lock, opal_mutex_t); OBJ_CONSTRUCT(&cond, opal_condition_t); OBJ_CONSTRUCT(&progress_thread, opal_thread_t); progress_thread.t_run = progress_engine; if (OPAL_SUCCESS != opal_thread_start(&progress_thread)) { fprintf(stderr, "Unable to start progress thread\n"); orte_event_base_finalize(my_base); exit(1); } /* wait a little while - reflects reality in an async system */ while (count < 100) { nanosleep(&tp, NULL); count++; } count=0; /* make a dummy event */ fprintf(stderr, "activating the write_event"); foo = OBJ_NEW(foo_caddy_t); opal_event_set(my_base, &foo->write_event, -1, 0, send_handler, foo); /* activate it. */ opal_event_active(&foo->write_event, EV_WRITE, 1); /* wait for it to trigger */ while (!fd_written && count < 1000) { if (0 == (count % 100)) { fprintf(stderr, "Waiting...\n"); } nanosleep(&tp, NULL); count++; } /* stop the thread */ OPAL_ACQUIRE_THREAD(&lock, &cond, &active); progress_thread_stop = true; OPAL_RELEASE_THREAD(&lock, &cond, &active); opal_fd_write(progress_thread_pipe[1], 1, &byte); opal_thread_join(&progress_thread, NULL); /* release the base */ fprintf(stderr, "Cleaning up\n"); opal_finalize(); fprintf(stderr, "Cleanup completed\n"); return 0; }