static int wrap_pthread_key_delete(pthread_key_t key) { /* this is clumsy: having to key_create lessens key_delete's chances of being interrupted - test not definite */ int err2; WRAP_START while( !(err2 = pthread_key_create(&key, NULL)) && !(err = pthread_key_delete(key)) ); if (err2) err = -3; //meaning the dependecy failed WRAP_END }
static void _MXML_FINI(void) { _mxml_global_t *global; /* Global data */ if (_mxml_key != -1) { if ((global = (_mxml_global_t *)pthread_getspecific(_mxml_key)) != NULL) _mxml_destructor(global); pthread_key_delete(_mxml_key); _mxml_key = -1; } }
int tMPI_Thread_key_delete(tMPI_Thread_key_t key) { int ret; ret=pthread_key_delete((key.key->pkey)); free(key.key); if(ret!=0) { tMPI_Fatal_error(TMPI_FARGS,"Failed to delete thread key, rc=%d.",ret); fflush(stderr); } return ret; }
void delete_msgque(void *arg) { msgque_t que = (msgque_t)arg; lnode *n; if(que->destroy_function){ while((n = LLIST_POP(lnode*,&que->share_que))!=NULL) que->destroy_function((void*)n); } mutex_destroy(&que->mtx); pthread_key_delete(que->t_key); free(que); #ifdef _DEBUG printf("on_que_destroy\n"); #endif }
bool OS_FreeTLSIndex(OS_TLSIndex nIndex) { if (nIndex == OS_INVALID_TLS_INDEX) { assert(0 && "OS_SetTLSValue(): Invalid TLS Index"); return false; } // // Delete the global pool key. // if (pthread_key_delete(nIndex) == 0) return true; else return false; }
rtems_task Test_Thread( rtems_task_argument arg ) { void *argument = (void *) arg; int sc; puts( "Test_Thread - key pthread_setspecific - OK" ); sc = pthread_setspecific( key, argument ); rtems_test_assert( !sc ); puts( "Test_Thread - pthread key delete - OK" ); sc = pthread_key_delete( key ); rtems_test_assert( sc == 0 ); puts( "Test_Thread - exit but don't run key destructors - OK" ); rtems_task_delete( RTEMS_SELF ); }
MachineThreads::~MachineThreads() { #if ENABLE(JSC_MULTIPLE_THREADS) if (m_threadSpecific) { int error = pthread_key_delete(m_threadSpecific); ASSERT_UNUSED(error, !error); } MutexLocker registeredThreadsLock(m_registeredThreadsMutex); for (Thread* t = m_registeredThreads; t;) { Thread* next = t->next; delete t; t = next; } #endif }
/** stop checklocks */ void checklock_stop(void) { if(key_created) { int i; key_deleted = 1; if(check_locking_order) fclose(thread_infos[0]->order_info); free(thread_infos[0]); thread_infos[0] = NULL; for(i = 0; i < THRDEBUG_MAX_THREADS; i++) log_assert(thread_infos[i] == NULL); /* should have been cleaned up. */ LOCKRET(pthread_key_delete(thr_debug_key)); key_created = 0; } }
static int wrap_pthread_key_create(pthread_key_t *key, void (*destructor)(void*)) { /* this is clumsy: having to key_create lessens key_delete's chances of being interrupted - test not definite */ int err2; WRAP_START while( !(err = pthread_key_create(key, destructor)) && !(err2 = pthread_key_delete(*key)) ); if (!err && err2) err = -3; //meaning the dependecy failed WRAP_END }
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved) { JNIEnv *env; destroy_native_crash_handler(); if (jvm->GetEnv((void **) &env, JNI_VERSION)) return; env->DeleteGlobalRef(gfq.clazz); env->DeleteGlobalRef(gfq.String.clazz); env->DeleteGlobalRef(gfq.IllegalArgumentException.clazz); pthread_key_delete(jni_env_key); }
/** * Simple holder of work-arounds for link-time issues. */ void workaroundHook() { pthread_key_t key = {0}; int ret = pthread_key_create(&key, NULL); if (!ret) { void *ptr = pthread_getspecific(key); // should return NULL ret = pthread_setspecific(key, &ptr); if (ret) { // Something went wrong. Since this is a stub, we don't care. } pthread_key_delete(key); } }
int main(void) { pthread_t thid1; int status; pthread_key_create(&keyid,NULL); if (pthread_create(&thid1,NULL,(void *)func2,NULL)) printf("创建线程1失败\n"); printf("主线程:%lu\n",pthread_self()); pthread_join(thid1,(void *)&status); pthread_key_delete(keyid); return 0; }
void PoolMemoryAllocator::cleanup() { BlockChainPtr p = s_blocks; while(p != 0) { BlockChainPtr pNext = p->m_next; free(p); p = pNext; } #ifndef OGDF_MEMORY_POOL_NTS #ifdef OGDF_NO_COMPILER_TLS pthread_key_delete(s_tpKey); #endif delete s_criticalSection; #endif }
void git_threads_shutdown(void) { if (_tls_init) { void *ptr = pthread_getspecific(_tls_key); pthread_setspecific(_tls_key, NULL); git__free(ptr); } pthread_key_delete(_tls_key); _tls_init = 0; git_mutex_free(&git__mwindow_mutex); /* Shut down any subsystems that have global state */ git_hash_global_shutdown(); git_futils_dirs_free(); }
int main() { pthread_t tid[THREAD_NUM]; int i; pthread_key_create(&key, NULL); #pragma omp parallel for for ( i = 0; i < THREAD_NUM; i++ ) pthread_create(&tid[i], NULL, thread, NULL); #pragma omp parallel for for ( i = 0; i < THREAD_NUM; i++ ) pthread_join(tid[i], NULL); pthread_key_delete(key); return 0; }
/* Shutdown TSRM (call once for the entire process) */ TSRM_API void tsrm_shutdown(void) { int i; if (tsrm_tls_table) { for (i=0; i<tsrm_tls_table_size; i++) { tsrm_tls_entry *p = tsrm_tls_table[i], *next_p; while (p) { int j; next_p = p->next; for (j=0; j<p->count; j++) { if (p->storage[j]) { if (resource_types_table && !resource_types_table[j].done && resource_types_table[j].dtor) { resource_types_table[j].dtor(p->storage[j], &p->storage); } free(p->storage[j]); } } free(p->storage); free(p); p = next_p; } } free(tsrm_tls_table); tsrm_tls_table = NULL; } if (resource_types_table) { free(resource_types_table); resource_types_table=NULL; } tsrm_mutex_free(tsmm_mutex); tsmm_mutex = NULL; TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Shutdown TSRM")); if (tsrm_error_file!=stderr) { fclose(tsrm_error_file); } #if defined(GNUPTH) pth_kill(); #elif defined(PTHREADS) pthread_setspecific(tls_key, 0); pthread_key_delete(tls_key); #elif defined(TSRM_WIN32) TlsFree(tls_key); #endif }
int do_test (void) { pthread_key_t keys[N]; int i; for (i = 0; i < N; ++i) if (pthread_key_create (&keys[i], fcts[i]) != 0) { write (2, "key_create failed\n", 18); _exit (1); } pthread_t th; if (pthread_create (&th, NULL, tf, &keys[1]) != 0) { write (2, "create failed\n", 14); _exit (1); } if (pthread_join (th, NULL) != 0) { write (2, "join failed\n", 12); _exit (1); } if (cnt0 != 0) { write (2, "cnt0 != 0\n", 10); _exit (1); } if (cnt1 != 1) { write (2, "cnt1 != 1\n", 10); _exit (1); } for (i = 0; i < N; ++i) if (pthread_key_delete (keys[i]) != 0) { write (2, "key_delete failed\n", 18); _exit (1); } return 0; }
int di_rwlock_destroy(di_rwlock_t * self) { int retval; if (dirw == NULL) return EINVAL; retval = pthread_mutex_destroy(&self->writers_mutex); if (retval != 0) return retval; retval = pthread_rwlock_destroy(&self->rwlock1); if (retval != 0) return retval; retval = pthread_rwlock_destroy(&self->rwlock2); if (retval != 0) return retval; retval = pthread_key_delete(self->key); if (retval != 0) return retval; self->instance1 = NULL; self->instance2 = NULL; return 0; }
int main(void) { int tid1,tid2; int cycle = 100; pthread_key_create(&key,NULL); while(cycle--) { pthread_create(&tid1,NULL,child1,NULL); pthread_create(&tid2,NULL,child2,NULL); } sleep(10); pthread_key_delete(key); printf("main thread exit\n"); return 0; }
/* 关闭log文件 */ int close_logger(int thread_num) { int i, ret; /* 关闭log文件 */ for (i = 0; i < thread_num; i++) { if (log_file[i]) { ret = fclose(log_file[i]); log_file[i] = NULL; } } /* 删除log id变量 */ pthread_key_delete(log_id); return ret; }
int stresscpu_thread_key_delete(stresscpu_thread_key_t key) { int ret; ret=pthread_key_delete(key->pthread_key); if(ret!=0) { fprintf(stderr, "Error [%s, line %d]: Failed to delete thread key, rc=%d.\n", __FILE__,__LINE__,ret); fflush(stderr); } return ret; }
void git_threads_shutdown(void) { void *ptr = NULL; pthread_once_t new_once = PTHREAD_ONCE_INIT; if (git_atomic_dec(&git__n_inits) > 0) return; /* Shut down any subsystems that have global state */ git__shutdown(); ptr = pthread_getspecific(_tls_key); pthread_setspecific(_tls_key, NULL); git__free(ptr); pthread_key_delete(_tls_key); git_mutex_free(&git__mwindow_mutex); _once_init = new_once; }
void onProcessDestruction() throw ( ::jace::JNIException ) { #ifdef SUPPORTS_PTHREADS int rc = pthread_key_delete( CLASSLOADER_KEY ); if ( rc != 0 ) { std::string msg = "JNIHelper::setClassLoader()\n" "thread_key_delete() returned " + std::to_string( rc ) + "."; throw JNIException( msg ); } #elif _WIN32 BOOL rc = TlsFree( CLASSLOADER_KEY ); if ( !rc ) { std::string msg = "JNIHelper::setClassLoader()\n" "TlsFree() returned " + std::to_string( GetLastError() ) + "."; throw JNIException( msg ); } #endif }
int main(int argc, char** argv) { printf("Starting dtls test.\n"); for(int i=0; i<NUM_PTHREAD_KEYS; i++) { pthread_key_create(&pthread_keys[i], dtls_dtor); } for (int i = 0; i < NR_TEST_THREADS; i++) { if (pthread_create(&my_threads[i], NULL, &thread, NULL)) perror("pth_create failed"); } for (int i = 0; i < NR_TEST_THREADS; i++) { pthread_join(my_threads[i], &my_retvals[i]); } for(int i=0; i<NUM_PTHREAD_KEYS; i++) { pthread_key_delete(pthread_keys[i]); } printf("Test complete!\n"); }
LIBXSMM_API int libxsmm_trace_finalize(void) { int result; #if defined(LIBXSMM_TRACE) result = EXIT_SUCCESS; if (0 <= internal_trace_initialized) { internal_trace_initialized = -1; /* disable */ # if defined(_WIN32) || defined(__CYGWIN__) result = (FALSE != SymCleanup(GetCurrentProcess()) ? EXIT_SUCCESS : GetLastError()); # elif !defined(LIBXSMM_NO_SYNC) result = pthread_key_delete(internal_trace_key); # endif } #else result = EXIT_FAILURE; #endif return result; }
int main(void) { int status ; pthread_t thid1, thid2 ; pthread_key_create (&key, NULL) ; if (pthread_create (&thid1, NULL, (void *)thread1, NULL) != 0 ) { /*创建新线程1*/ printf ("new thread create failed\n") ; return 0 ; } if (pthread_create (&thid2, NULL, (void *)thread2, NULL) != 0 ) { /*创建新线程2*/ printf ("new thread create failed\n") ; return 0 ; } pthread_join (thid1, &status) ; pthread_join (thid2, &status) ; pthread_key_delete (key) ; return 0 ; }
void CProfiler2::Shutdown() { ENSURE(m_Initialised); ENSURE(!m_GPU); // must shutdown GPU before profiler if (m_MgContext) { mg_stop(m_MgContext); m_MgContext = NULL; } // TODO: free non-NULL keys, instead of leaking them int err = pthread_key_delete(m_TLS); ENSURE(err == 0); m_Initialised = false; }
/* * This function should be called by the user when the process ends, * to free the local storage index */ ITT_EXTERN_C void JITAPI FinalizeProcess() { if (m_libHandle) { #if ITT_PLATFORM==ITT_PLATFORM_WIN FreeLibrary(m_libHandle); #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ dlclose(m_libHandle); #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ m_libHandle = NULL; } if (threadLocalStorageHandle) #if ITT_PLATFORM==ITT_PLATFORM_WIN TlsFree (threadLocalStorageHandle); #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */ pthread_key_delete(threadLocalStorageHandle); #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ }
static KDvoid _xmFreeTS ( KDvoid* f ) { XMThreadStorage* ts = (XMThreadStorage *) f; KDvoid* value = 0; if ( ts ) { value = (KDvoid *) pthread_getspecific ( ts->pkey ); if ( value ) { kdFree ( value ); pthread_setspecific ( ts->pkey, 0 ); } pthread_key_delete ( ts->pkey ); kdFree ( ts ); } }
int rtems_gxx_key_delete (__gthread_key_t key) { int eno = 0; pthread_key_t *pkey = key; #ifdef DEBUG_GXX_WRAPPERS printk( "gxx_wrappers: delete key=%x\n", pkey ); #endif if ( pkey == NULL ) { return EINVAL; } eno = pthread_key_delete(*pkey); if ( eno == 0 ) { free( pkey ); } return eno; }