threads.doxy 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2016, 2017 CNRS
  5. * Copyright (C) 2011, 2012 INRIA
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \defgroup API_Threads Threads
  9. \brief This section describes the thread facilities provided
  10. by StarPU. The thread function are either implemented on top of the
  11. pthread library or the Simgrid library when the simulated performance
  12. mode is enabled (\ref SimGridSupport).
  13. \def STARPU_PTHREAD_CREATE_ON
  14. \ingroup API_Threads
  15. Call starpu_pthread_create_on() and abort on error.
  16. \def STARPU_PTHREAD_CREATE
  17. \ingroup API_Threads
  18. Call starpu_pthread_create() and abort on error.
  19. \def STARPU_PTHREAD_MUTEX_INIT
  20. \ingroup API_Threads
  21. Call starpu_pthread_mutex_init() and abort on error.
  22. \def STARPU_PTHREAD_MUTEX_DESTROY
  23. \ingroup API_Threads
  24. Call starpu_pthread_mutex_destroy() and abort on error.
  25. \def STARPU_PTHREAD_MUTEX_LOCK
  26. \ingroup API_Threads
  27. Call starpu_pthread_mutex_lock() and abort on error.
  28. \def STARPU_PTHREAD_MUTEX_UNLOCK
  29. \ingroup API_Threads
  30. Call starpu_pthread_mutex_unlock() and abort on error.
  31. \def STARPU_PTHREAD_KEY_CREATE
  32. \ingroup API_Threads
  33. Call starpu_pthread_key_create() and abort on error.
  34. \def STARPU_PTHREAD_KEY_DELETE
  35. \ingroup API_Threads
  36. Call starpu_pthread_key_delete() and abort on error.
  37. \def STARPU_PTHREAD_SETSPECIFIC
  38. \ingroup API_Threads
  39. Call starpu_pthread_setspecific() and abort on error.
  40. \def STARPU_PTHREAD_GETSPECIFIC
  41. \ingroup API_Threads
  42. Call starpu_pthread_getspecific() and abort on error.
  43. \def STARPU_PTHREAD_RWLOCK_INIT
  44. \ingroup API_Threads
  45. Call starpu_pthread_rwlock_init() and abort on error.
  46. \def STARPU_PTHREAD_RWLOCK_RDLOCK
  47. \ingroup API_Threads
  48. Call starpu_pthread_rwlock_rdlock() and abort on error.
  49. \def STARPU_PTHREAD_RWLOCK_WRLOCK
  50. \ingroup API_Threads
  51. Call starpu_pthread_rwlock_wrlock() and abort on error.
  52. \def STARPU_PTHREAD_RWLOCK_UNLOCK
  53. \ingroup API_Threads
  54. Call starpu_pthread_rwlock_unlock() and abort on error.
  55. \def STARPU_PTHREAD_RWLOCK_DESTROY
  56. \ingroup API_Threads
  57. Call starpu_pthread_rwlock_destroy() and abort on error.
  58. \def STARPU_PTHREAD_COND_INIT
  59. \ingroup API_Threads
  60. Call starpu_pthread_cond_init() and abort on error.
  61. \def STARPU_PTHREAD_COND_DESTROY
  62. \ingroup API_Threads
  63. Call starpu_pthread_cond_destroy() and abort on error.
  64. \def STARPU_PTHREAD_COND_SIGNAL
  65. \ingroup API_Threads
  66. Call starpu_pthread_cond_signal() and abort on error.
  67. \def STARPU_PTHREAD_COND_BROADCAST
  68. \ingroup API_Threads
  69. Call starpu_pthread_cond_broadcast() and abort on error.
  70. \def STARPU_PTHREAD_COND_WAIT
  71. \ingroup API_Threads
  72. Call starpu_pthread_cond_wait() and abort on error.
  73. \def STARPU_PTHREAD_BARRIER_INIT
  74. \ingroup API_Threads
  75. Call starpu_pthread_barrier_init() and abort on error.
  76. \def STARPU_PTHREAD_BARRIER_DESTROY
  77. \ingroup API_Threads
  78. Call starpu_pthread_barrier_destroy() and abort on error.
  79. \def STARPU_PTHREAD_BARRIER_WAIT
  80. \ingroup API_Threads
  81. Call starpu_pthread_barrier_wait() and abort on error.
  82. \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)
  83. \ingroup API_Threads
  84. \fn int starpu_pthread_create(starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)
  85. \ingroup API_Threads
  86. Start a new thread in the calling process. The new
  87. thread starts execution by invoking \p start_routine; \p arg is passed
  88. as the sole argument of \p start_routine.
  89. \fn int starpu_pthread_join(starpu_pthread_t thread, void **retval)
  90. \ingroup API_Threads
  91. Wait for the thread specified by \p thread to
  92. terminate. If that thread has already terminated, then the function
  93. returns immediately. The thread specified by \p thread must be
  94. joinable.
  95. \fn int starpu_pthread_exit(void *retval)
  96. \ingroup API_Threads
  97. Terminate the calling thread and return a value via
  98. \p retval that (if the thread is joinable) is available to another thread
  99. in the same process that calls starpu_pthread_join().
  100. \fn int starpu_pthread_attr_init(starpu_pthread_attr_t *attr)
  101. \ingroup API_Threads
  102. Initialize the thread attributes object pointed to by
  103. \p attr with default attribute values.
  104. Do not do anything when the simulated performance mode is enabled
  105. (\ref SimGridSupport).
  106. \fn int starpu_pthread_attr_destroy(starpu_pthread_attr_t *attr)
  107. \ingroup API_Threads
  108. Destroy a thread attributes object which is no longer
  109. required. Destroying a thread attributes object has no effect on
  110. threads that were created using that object.
  111. Do not do anything when the simulated performance mode is enabled
  112. (\ref SimGridSupport).
  113. \fn int starpu_pthread_attr_setdetachstate(starpu_pthread_attr_t *attr, int detachstate)
  114. \ingroup API_Threads
  115. Set the detach state attribute of the thread attributes
  116. object referred to by \p attr to the value specified in \p
  117. detachstate. The detach state attribute determines whether a thread
  118. created using the thread attributes object \p attr will be created in
  119. a joinable or a detached state.
  120. Do not do anything when the simulated performance mode is enabled
  121. (\ref SimGridSupport).
  122. \fn int starpu_pthread_mutex_init(starpu_pthread_mutex_t *mutex, const starpu_pthread_mutexattr_t *mutexattr)
  123. \ingroup API_Threads
  124. Initialize the mutex object pointed to by \p mutex
  125. according to the mutex attributes specified in \p mutexattr. If \p
  126. mutexattr is <c>NULL</c>, default attributes are used instead.
  127. \fn int starpu_pthread_mutex_destroy(starpu_pthread_mutex_t *mutex)
  128. \ingroup API_Threads
  129. Destroy a mutex object, and free the resources it might
  130. hold. The mutex must be unlocked on entrance.
  131. \fn int starpu_pthread_mutex_lock(starpu_pthread_mutex_t *mutex)
  132. \ingroup API_Threads
  133. Lock the given \p mutex. If \p mutex is currently
  134. unlocked, it becomes locked and owned by the calling thread, and the
  135. function returns immediately. If \p mutex is already locked by
  136. another thread, the function suspends the calling thread until
  137. \p mutex is unlocked.
  138. This function also produces trace when the configure option
  139. \ref enable-fxt-lock "--enable-fxt-lock" is enabled.
  140. \fn int starpu_pthread_mutex_unlock(starpu_pthread_mutex_t *mutex)
  141. \ingroup API_Threads
  142. Unlock the given \p mutex. The mutex is assumed to be
  143. locked and owned by the calling thread on entrance to
  144. starpu_pthread_mutex_unlock().
  145. This function also produces trace when the configure option
  146. \ref enable-fxt-lock "--enable-fxt-lock" is enabled.
  147. \fn int starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex)
  148. \ingroup API_Threads
  149. Behave identically to starpu_pthread_mutex_lock(),
  150. except that it does not block the calling thread if the mutex is
  151. already locked by another thread (or by the calling thread in the case
  152. of a ``fast'' mutex). Instead, the function returns immediately with
  153. the error code \c EBUSY.
  154. This function also produces trace when the configure option
  155. \ref enable-fxt-lock "--enable-fxt-lock" is enabled.
  156. \typedef STARPU_PTHREAD_MUTEX_INITIALIZER
  157. \ingroup API_Threads
  158. Initialize the mutex given in parameter.
  159. \fn int starpu_pthread_mutexattr_gettype(const starpu_pthread_mutexattr_t *attr, int *type)
  160. \ingroup API_Threads
  161. todo
  162. \fn int starpu_pthread_mutexattr_settype(starpu_pthread_mutexattr_t *attr, int type)
  163. \ingroup API_Threads
  164. todo
  165. \fn int starpu_pthread_mutexattr_destroy(starpu_pthread_mutexattr_t *attr)
  166. \ingroup API_Threads
  167. todo
  168. \fn int starpu_pthread_mutexattr_init(starpu_pthread_mutexattr_t *attr)
  169. \ingroup API_Threads
  170. todo
  171. \fn int starpu_pthread_key_create(starpu_pthread_key_t *key, void (*destr_function) (void *))
  172. \ingroup API_Threads
  173. Allocate a new TSD key. The key is stored in the
  174. location pointed to by \p key.
  175. \fn int starpu_pthread_key_delete(starpu_pthread_key_t key)
  176. \ingroup API_Threads
  177. Deallocate a TSD key. Do not check whether
  178. non-<c>NULL</c> values are associated with that key in the currently
  179. executing threads, nor call the destructor function associated with
  180. the key.
  181. \fn int starpu_pthread_setspecific(starpu_pthread_key_t key, const void *pointer)
  182. \ingroup API_Threads
  183. Change the value associated with \p key in the calling
  184. thread, storing the given \p pointer instead.
  185. \fn void *starpu_pthread_getspecific(starpu_pthread_key_t key)
  186. \ingroup API_Threads
  187. Return the value associated with \p key on success, and
  188. <c>NULL</c> on error.
  189. \typedef STARPU_PTHREAD_COND_INITIALIZER
  190. \ingroup API_Threads
  191. Initialize the condition variable given in parameter.
  192. \fn int starpu_pthread_cond_init(starpu_pthread_cond_t *cond, starpu_pthread_condattr_t *cond_attr)
  193. \ingroup API_Threads
  194. Initialize the condition variable \p cond, using the
  195. condition attributes specified in \p cond_attr, or default attributes
  196. if \p cond_attr is <c>NULL</c>.
  197. \fn int starpu_pthread_cond_signal(starpu_pthread_cond_t *cond)
  198. \ingroup API_Threads
  199. Restart one of the threads that are waiting on the
  200. condition variable \p cond. If no threads are waiting on \p cond,
  201. nothing happens. If several threads are waiting on \p cond, exactly
  202. one is restarted, but it is not specified which.
  203. \fn int starpu_pthread_cond_broadcast(starpu_pthread_cond_t *cond)
  204. \ingroup API_Threads
  205. Restart all the threads that are waiting on the
  206. condition variable \p cond. Nothing happens if no threads are waiting on \p cond.
  207. \fn int starpu_pthread_cond_wait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex)
  208. \ingroup API_Threads
  209. Atomically unlock \p mutex (as per
  210. starpu_pthread_mutex_unlock()) and wait for the condition variable \p cond
  211. to be signaled. The thread execution is suspended and does not consume
  212. any CPU time until the condition variable is signaled. The mutex must
  213. be locked by the calling thread on entrance to
  214. starpu_pthread_cond_wait(). Before returning to the calling thread, the
  215. function re-acquires mutex (as per starpu_pthread_mutex_lock()).
  216. This function also produces trace when the configure option
  217. \ref enable-fxt-lock "--enable-fxt-lock" is enabled.
  218. \fn int starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex, const struct timespec *abstime)
  219. \ingroup API_Threads
  220. Atomicall unlocks \p mutex and wait on \p cond, as
  221. starpu_pthread_cond_wait() does, but also bound the duration of
  222. the wait with \p abstime.
  223. \fn int starpu_pthread_cond_destroy(starpu_pthread_cond_t *cond)
  224. \ingroup API_Threads
  225. Destroy a condition variable, freeing the resources it
  226. might hold. No threads must be waiting on the condition variable on
  227. entrance to the function.
  228. \fn int starpu_pthread_rwlock_init(starpu_pthread_rwlock_t *rwlock, const starpu_pthread_rwlockattr_t *attr)
  229. \ingroup API_Threads
  230. Similar to starpu_pthread_mutex_init().
  231. \fn int starpu_pthread_rwlock_destroy(starpu_pthread_rwlock_t *rwlock)
  232. \ingroup API_Threads
  233. Similar to starpu_pthread_mutex_destroy().
  234. \fn int starpu_pthread_rwlock_rdlock(starpu_pthread_rwlock_t *rwlock)
  235. \ingroup API_Threads
  236. Similar to starpu_pthread_mutex_lock().
  237. \fn int starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock)
  238. \ingroup API_Threads
  239. todo
  240. \fn int starpu_pthread_rwlock_wrlock(starpu_pthread_rwlock_t *rwlock)
  241. \ingroup API_Threads
  242. Similar to starpu_pthread_mutex_lock().
  243. \fn int starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock)
  244. \ingroup API_Threads
  245. todo
  246. \fn int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock)
  247. \ingroup API_Threads
  248. Similar to starpu_pthread_mutex_unlock().
  249. \fn int starpu_pthread_barrier_init(starpu_pthread_barrier_t *barrier, const starpu_pthread_barrierattr_t *attr, unsigned count)
  250. \ingroup API_Threads
  251. todo
  252. \fn int starpu_pthread_barrier_destroy(starpu_pthread_barrier_t *barrier)
  253. \ingroup API_Threads
  254. todo
  255. \fn int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier)
  256. \ingroup API_Threads
  257. todo
  258. \fn int starpu_pthread_spin_init(starpu_pthread_spinlock_t *lock, int pshared)
  259. \ingroup API_Threads
  260. todo
  261. \fn int starpu_pthread_spin_destroy(starpu_pthread_spinlock_t *lock)
  262. \ingroup API_Threads
  263. todo
  264. \fn int starpu_pthread_spin_lock(starpu_pthread_spinlock_t *lock)
  265. \ingroup API_Threads
  266. todo
  267. \fn int starpu_pthread_spin_trylock(starpu_pthread_spinlock_t *lock)
  268. \ingroup API_Threads
  269. todo
  270. \fn int starpu_pthread_spin_unlock(starpu_pthread_spinlock_t *lock)
  271. \ingroup API_Threads
  272. todo
  273. \fn void starpu_sleep(float nb_sec)
  274. \ingroup API_Threads
  275. Similar to calling Unix' \c sleep function, except that it takes a float
  276. to allow sub-second sleeping, and when StarPU is compiled in simgrid mode it
  277. does not really sleep but just makes simgrid record that the thread has taken
  278. some time to sleep.
  279. */