| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 | /* StarPU --- Runtime system for heterogeneous multicore architectures. * * Copyright (C) 2010-2017, 2019                          CNRS * Copyright (C) 2009-2011,2014,2016                      Université de Bordeaux * Copyright (C) 2011,2012                                Inria * * StarPU is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or (at * your option) any later version. * * StarPU is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Lesser General Public License in COPYING.LGPL for more details. *//*! \defgroup API_Threads Threads\brief This section describes the thread facilities providedby StarPU. The thread function are either implemented on top of thepthread library or the SimGrid library when the simulated performancemode is enabled (\ref SimGridSupport).\def STARPU_PTHREAD_CREATE_ON\ingroup API_ThreadsCall starpu_pthread_create_on() and abort on error.\def STARPU_PTHREAD_CREATE\ingroup API_ThreadsCall starpu_pthread_create() and abort on error.\def STARPU_PTHREAD_MUTEX_INIT\ingroup API_ThreadsCall starpu_pthread_mutex_init() and abort on error.\def STARPU_PTHREAD_MUTEX_DESTROY\ingroup API_ThreadsCall starpu_pthread_mutex_destroy() and abort on error.\def STARPU_PTHREAD_MUTEX_LOCK\ingroup API_ThreadsCall starpu_pthread_mutex_lock() and abort on error.\def STARPU_PTHREAD_MUTEX_UNLOCK\ingroup API_ThreadsCall starpu_pthread_mutex_unlock() and abort on error.\def STARPU_PTHREAD_KEY_CREATE\ingroup API_ThreadsCall starpu_pthread_key_create() and abort on error.\def STARPU_PTHREAD_KEY_DELETE\ingroup API_ThreadsCall starpu_pthread_key_delete() and abort on error.\def STARPU_PTHREAD_SETSPECIFIC\ingroup API_ThreadsCall starpu_pthread_setspecific() and abort on error.\def STARPU_PTHREAD_GETSPECIFIC\ingroup API_ThreadsCall starpu_pthread_getspecific() and abort on error.\def STARPU_PTHREAD_RWLOCK_INIT\ingroup API_ThreadsCall starpu_pthread_rwlock_init() and abort on error.\def STARPU_PTHREAD_RWLOCK_RDLOCK\ingroup API_ThreadsCall starpu_pthread_rwlock_rdlock() and abort on error.\def STARPU_PTHREAD_RWLOCK_WRLOCK\ingroup API_ThreadsCall starpu_pthread_rwlock_wrlock() and abort on error.\def STARPU_PTHREAD_RWLOCK_UNLOCK\ingroup API_ThreadsCall starpu_pthread_rwlock_unlock() and abort on error.\def STARPU_PTHREAD_RWLOCK_DESTROY\ingroup API_ThreadsCall starpu_pthread_rwlock_destroy() and abort on error.\def STARPU_PTHREAD_COND_INIT\ingroup API_ThreadsCall starpu_pthread_cond_init() and abort on error.\def STARPU_PTHREAD_COND_DESTROY\ingroup API_ThreadsCall starpu_pthread_cond_destroy() and abort on error.\def STARPU_PTHREAD_COND_SIGNAL\ingroup API_ThreadsCall starpu_pthread_cond_signal() and abort on error.\def STARPU_PTHREAD_COND_BROADCAST\ingroup API_ThreadsCall starpu_pthread_cond_broadcast() and abort on error.\def STARPU_PTHREAD_COND_WAIT\ingroup API_ThreadsCall starpu_pthread_cond_wait() and abort on error.\def STARPU_PTHREAD_BARRIER_INIT\ingroup API_ThreadsCall starpu_pthread_barrier_init() and abort on error.\def STARPU_PTHREAD_BARRIER_DESTROY\ingroup API_ThreadsCall starpu_pthread_barrier_destroy() and abort on error.\def STARPU_PTHREAD_BARRIER_WAIT\ingroup API_ThreadsCall starpu_pthread_barrier_wait() and abort on error.\fn int starpu_pthread_create_on(char *name, starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg, int where)\ingroup API_Threads\fn int starpu_pthread_create(starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)\ingroup API_ThreadsStart a new thread in the calling process. The newthread starts execution by invoking \p start_routine; \p arg is passedas the sole argument of \p start_routine.\fn int starpu_pthread_join(starpu_pthread_t thread, void **retval)\ingroup API_ThreadsWait for the thread specified by \p thread toterminate.  If that thread has already terminated, then the functionreturns immediately. The thread specified by \p thread must bejoinable.\fn int starpu_pthread_exit(void *retval)\ingroup API_ThreadsTerminate the calling thread and return a value via\p retval that (if the thread is joinable) is available to another threadin the same process that calls starpu_pthread_join().\fn int starpu_pthread_attr_init(starpu_pthread_attr_t *attr)\ingroup API_ThreadsInitialize the thread attributes object pointed to by\p attr with default attribute values.Do not do anything when the simulated performance mode is enabled(\ref SimGridSupport).\fn int starpu_pthread_attr_destroy(starpu_pthread_attr_t *attr)\ingroup API_ThreadsDestroy a thread attributes object which is no longerrequired. Destroying a thread attributes object has no effect onthreads that were created using that object.Do not do anything when the simulated performance mode is enabled(\ref SimGridSupport).\fn int starpu_pthread_attr_setdetachstate(starpu_pthread_attr_t *attr, int detachstate)\ingroup API_ThreadsSet the detach state attribute of the thread attributesobject referred to by \p attr to the value specified in \pdetachstate.  The detach state attribute determines whether a threadcreated using the thread attributes object \p attr will be created ina joinable or a detached state.Do not do anything when the simulated performance mode is enabled(\ref SimGridSupport).\fn int starpu_pthread_mutex_init(starpu_pthread_mutex_t *mutex, const starpu_pthread_mutexattr_t *mutexattr)\ingroup API_ThreadsInitialize the mutex object pointed to by \p mutexaccording to the mutex attributes specified in \p mutexattr.  If \pmutexattr is <c>NULL</c>, default attributes are used instead.\fn int starpu_pthread_mutex_destroy(starpu_pthread_mutex_t *mutex)\ingroup API_ThreadsDestroy a mutex object, and free the resources it mighthold. The mutex must be unlocked on entrance.\fn int starpu_pthread_mutex_lock(starpu_pthread_mutex_t *mutex)\ingroup API_ThreadsLock the given \p mutex. If \p mutex is currentlyunlocked, it becomes locked and owned by the calling thread, and thefunction returns immediately. If \p mutex is already locked byanother thread, the function suspends the calling thread until\p mutex is unlocked.This function also produces trace when the configure option\ref enable-fxt-lock "--enable-fxt-lock" is enabled.\fn int starpu_pthread_mutex_unlock(starpu_pthread_mutex_t *mutex)\ingroup API_ThreadsUnlock the given \p mutex. The mutex is assumed to belocked and owned by the calling thread on entrance tostarpu_pthread_mutex_unlock().This function also produces trace when the configure option\ref enable-fxt-lock "--enable-fxt-lock" is enabled.\fn int starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex)\ingroup API_ThreadsBehave identically to starpu_pthread_mutex_lock(),except that it does not block the calling thread if the mutex isalready locked by another thread (or by the calling thread in the caseof a ``fast''  mutex). Instead, the function returns immediately withthe error code \c EBUSY.This function also produces trace when the configure option\ref enable-fxt-lock "--enable-fxt-lock" is enabled.\typedef STARPU_PTHREAD_MUTEX_INITIALIZER\ingroup API_ThreadsInitialize the mutex given in parameter.\fn int starpu_pthread_mutexattr_gettype(const starpu_pthread_mutexattr_t *attr, int *type)\ingroup API_Threadstodo\fn int starpu_pthread_mutexattr_settype(starpu_pthread_mutexattr_t *attr, int type)\ingroup API_Threadstodo\fn int starpu_pthread_mutexattr_destroy(starpu_pthread_mutexattr_t *attr)\ingroup API_Threadstodo\fn int starpu_pthread_mutexattr_init(starpu_pthread_mutexattr_t *attr)\ingroup API_Threadstodo\fn int starpu_pthread_key_create(starpu_pthread_key_t *key, void (*destr_function) (void *))\ingroup API_ThreadsAllocate a new TSD key. The key is stored in thelocation pointed to by \p key.\fn int starpu_pthread_key_delete(starpu_pthread_key_t key)\ingroup API_ThreadsDeallocate a TSD key. Do not check whethernon-<c>NULL</c> values are associated with that key in the currentlyexecuting threads, nor call the destructor function associated withthe key.\fn int starpu_pthread_setspecific(starpu_pthread_key_t key, const void *pointer)\ingroup API_ThreadsChange the value associated with \p key in the callingthread, storing the given \p pointer instead.\fn void *starpu_pthread_getspecific(starpu_pthread_key_t key)\ingroup API_ThreadsReturn the value associated with \p key on success, and<c>NULL</c> on error.\typedef STARPU_PTHREAD_COND_INITIALIZER\ingroup API_ThreadsInitialize the condition variable given in parameter.\fn int starpu_pthread_cond_init(starpu_pthread_cond_t *cond, starpu_pthread_condattr_t *cond_attr)\ingroup API_ThreadsInitialize the condition variable \p cond, using thecondition attributes specified in \p cond_attr, or default attributesif \p cond_attr is <c>NULL</c>.\fn int starpu_pthread_cond_signal(starpu_pthread_cond_t *cond)\ingroup API_ThreadsRestart one of the threads that are waiting on thecondition variable \p cond. If no threads are waiting on \p cond,nothing happens. If several threads are waiting on \p cond, exactlyone is restarted, but it is not specified which.\fn int starpu_pthread_cond_broadcast(starpu_pthread_cond_t *cond)\ingroup API_ThreadsRestart all the threads that are waiting on thecondition variable \p cond. Nothing happens if no threads are waiting on \p cond.\fn int starpu_pthread_cond_wait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex)\ingroup API_ThreadsAtomically unlock \p mutex (as perstarpu_pthread_mutex_unlock()) and wait for the condition variable \p condto be signaled. The thread execution is suspended and does not consumeany CPU time until the condition variable is signaled. The mutex mustbe locked by the calling thread on entrance tostarpu_pthread_cond_wait(). Before returning to the calling thread, thefunction re-acquires mutex (as per starpu_pthread_mutex_lock()).This function also produces trace when the configure option\ref enable-fxt-lock "--enable-fxt-lock" is enabled.\fn int starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex, const struct timespec *abstime)\ingroup API_ThreadsAtomicall unlocks \p mutex and wait on \p cond, asstarpu_pthread_cond_wait() does, but also bound the duration ofthe wait with \p abstime.\fn int starpu_pthread_cond_destroy(starpu_pthread_cond_t *cond)\ingroup API_ThreadsDestroy a condition variable, freeing the resources itmight hold. No threads must be waiting on the condition variable onentrance to the function.\fn int starpu_pthread_rwlock_init(starpu_pthread_rwlock_t *rwlock, const starpu_pthread_rwlockattr_t *attr)\ingroup API_ThreadsSimilar to starpu_pthread_mutex_init().\fn int starpu_pthread_rwlock_destroy(starpu_pthread_rwlock_t *rwlock)\ingroup API_ThreadsSimilar to starpu_pthread_mutex_destroy().\fn int starpu_pthread_rwlock_rdlock(starpu_pthread_rwlock_t *rwlock)\ingroup API_ThreadsSimilar to starpu_pthread_mutex_lock().\fn int starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock)\ingroup API_Threadstodo\fn int starpu_pthread_rwlock_wrlock(starpu_pthread_rwlock_t *rwlock)\ingroup API_ThreadsSimilar to starpu_pthread_mutex_lock().\fn int starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock)\ingroup API_Threadstodo\fn int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock)\ingroup API_ThreadsSimilar to starpu_pthread_mutex_unlock().\fn int starpu_pthread_barrier_init(starpu_pthread_barrier_t *barrier, const starpu_pthread_barrierattr_t *attr, unsigned count)\ingroup API_Threadstodo\fn int starpu_pthread_barrier_destroy(starpu_pthread_barrier_t *barrier)\ingroup API_Threadstodo\fn int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier)\ingroup API_Threadstodo\fn int starpu_pthread_spin_init(starpu_pthread_spinlock_t *lock, int pshared)\ingroup API_Threadstodo\fn int starpu_pthread_spin_destroy(starpu_pthread_spinlock_t *lock)\ingroup API_Threadstodo\fn int starpu_pthread_spin_lock(starpu_pthread_spinlock_t *lock)\ingroup API_Threadstodo\fn int starpu_pthread_spin_trylock(starpu_pthread_spinlock_t *lock)\ingroup API_Threadstodo\fn int starpu_pthread_spin_unlock(starpu_pthread_spinlock_t *lock)\ingroup API_Threadstodo\fn void starpu_sleep(float nb_sec)\ingroup API_ThreadsSimilar to calling Unix' \c sleep function, except that it takes a floatto allow sub-second sleeping, and when StarPU is compiled in SimGrid mode itdoes not really sleep but just makes SimGrid record that the thread has takensome time to sleep.*/
 |