threads.doxy 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
  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 SimulatedPerformance).
  13. \def STARPU_PTHREAD_CREATE_ON
  14. \ingroup API_Threads
  15. This macro calls the function starpu_pthread_create_on() and aborts on error.
  16. \def STARPU_PTHREAD_CREATE
  17. \ingroup API_Threads
  18. This macro calls the function starpu_pthread_create() and aborts on error.
  19. \def STARPU_PTHREAD_MUTEX_INIT
  20. \ingroup API_Threads
  21. This macro calls the function starpu_pthread_mutex_init() and aborts
  22. on error.
  23. \def STARPU_PTHREAD_MUTEX_DESTROY
  24. \ingroup API_Threads
  25. This macro calls the function starpu_pthread_mutex_destroy() and
  26. aborts on error.
  27. \def STARPU_PTHREAD_MUTEX_LOCK
  28. \ingroup API_Threads
  29. This macro calls the function starpu_pthread_mutex_lock() and aborts
  30. on error.
  31. \def STARPU_PTHREAD_MUTEX_UNLOCK
  32. \ingroup API_Threads
  33. This macro calls the function starpu_pthread_mutex_unlock() and aborts
  34. on error.
  35. \def STARPU_PTHREAD_KEY_CREATE
  36. \ingroup API_Threads
  37. This macro calls the function starpu_pthread_key_create() and aborts
  38. on error.
  39. \def STARPU_PTHREAD_KEY_DELETE
  40. \ingroup API_Threads
  41. This macro calls the function starpu_pthread_key_delete() and aborts
  42. on error.
  43. \def STARPU_PTHREAD_SETSPECIFIC
  44. \ingroup API_Threads
  45. This macro calls the function starpu_pthread_setspecific() and aborts
  46. on error.
  47. \def STARPU_PTHREAD_GETSPECIFIC
  48. \ingroup API_Threads
  49. This macro calls the function starpu_pthread_getspecific() and aborts
  50. on error.
  51. \def STARPU_PTHREAD_RWLOCK_INIT
  52. \ingroup API_Threads
  53. This macro calls the function starpu_pthread_rwlock_init() and aborts
  54. on error.
  55. \def STARPU_PTHREAD_RWLOCK_RDLOCK
  56. \ingroup API_Threads
  57. This macro calls the function starpu_pthread_rwlock_rdlock() and
  58. aborts on error.
  59. \def STARPU_PTHREAD_RWLOCK_WRLOCK
  60. \ingroup API_Threads
  61. This macro calls the function starpu_pthread_rwlock_wrlock() and
  62. aborts on error.
  63. \def STARPU_PTHREAD_RWLOCK_UNLOCK
  64. \ingroup API_Threads
  65. This macro calls the function starpu_pthread_rwlock_unlock() and
  66. aborts on error.
  67. \def STARPU_PTHREAD_RWLOCK_DESTROY
  68. \ingroup API_Threads
  69. This macro calls the function starpu_pthread_rwlock_destroy() and
  70. aborts on error.
  71. \def STARPU_PTHREAD_COND_INIT
  72. \ingroup API_Threads
  73. This macro calls the function starpu_pthread_cond_init() and aborts on error.
  74. \def STARPU_PTHREAD_COND_DESTROY
  75. \ingroup API_Threads
  76. This macro calls the function starpu_pthread_cond_destroy() and aborts
  77. on error.
  78. \def STARPU_PTHREAD_COND_SIGNAL
  79. \ingroup API_Threads
  80. This macro calls the function starpu_pthread_cond_signal() and aborts
  81. on error.
  82. \def STARPU_PTHREAD_COND_BROADCAST
  83. \ingroup API_Threads
  84. This macro calls the function starpu_pthread_cond_broadcast() and
  85. aborts on error.
  86. \def STARPU_PTHREAD_COND_WAIT
  87. \ingroup API_Threads
  88. This macro calls the function starpu_pthread_cond_wait() and aborts on error.
  89. \def STARPU_PTHREAD_BARRIER_INIT
  90. \ingroup API_Threads
  91. This macro calls the function starpu_pthread_barrier_init() and aborts
  92. on error.
  93. \def STARPU_PTHREAD_BARRIER_DESTROY
  94. \ingroup API_Threads
  95. This macro calls the function starpu_pthread_barrier_destroy() and
  96. aborts on error.
  97. \def STARPU_PTHREAD_BARRIER_WAIT
  98. \ingroup API_Threads
  99. This macro calls the function starpu_pthread_barrier_wait() and aborts
  100. on error.
  101. \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)
  102. \ingroup API_Threads
  103. \fn int starpu_pthread_create(starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)
  104. \ingroup API_Threads
  105. This function starts a new thread in the calling process. The new
  106. thread starts execution by invoking \p start_routine; \p arg is passed
  107. as the sole argument of \p start_routine.
  108. \fn int starpu_pthread_join(starpu_pthread_t thread, void **retval)
  109. \ingroup API_Threads
  110. This function waits for the thread specified by \p thread to
  111. terminate. If that thread has already terminated, then the function
  112. returns immediately. The thread specified by \p thread must be
  113. joinable.
  114. \fn int starpu_pthread_attr_init(starpu_pthread_attr_t *attr)
  115. \ingroup API_Threads
  116. This function initializes the thread attributes object pointed to by
  117. \p attr with default attribute values.
  118. It does not do anything when the simulated performance mode is enabled
  119. (\ref SimulatedPerformance).
  120. \fn int starpu_pthread_attr_destroy(starpu_pthread_attr_t *attr)
  121. \ingroup API_Threads
  122. This function destroys a thread attributes object which is no longer
  123. required. Destroying a thread attributes object has no effect on
  124. threads that were created using that object.
  125. It does not do anything when the simulated performance mode is enabled
  126. (\ref SimulatedPerformance).
  127. \fn int starpu_pthread_attr_setdetachstate(starpu_pthread_attr_t *attr, int detachstate)
  128. \ingroup API_Threads
  129. This function sets the detach state attribute of the thread attributes
  130. object referred to by \p attr to the value specified in \p
  131. detachstate. The detach state attribute determines whether a thread
  132. created using the thread attributes object \p attr will be created in
  133. a joinable or a detached state.
  134. It does not do anything when the simulated performance mode is enabled
  135. (\ref SimulatedPerformance).
  136. \fn int starpu_pthread_mutex_init(starpu_pthread_mutex_t *mutex, const starpu_pthread_mutexattr_t *mutexattr)
  137. \ingroup API_Threads
  138. This function initializes the mutex object pointed to by \p mutex
  139. according to the mutex attributes specified in \p mutexattr. If \p
  140. mutexattr is NULL, default attributes are used instead.
  141. \fn int starpu_pthread_mutex_destroy(starpu_pthread_mutex_t *mutex)
  142. \ingroup API_Threads
  143. This function destroys a mutex object, freeing the resources it might
  144. hold. The mutex must be unlocked on entrance.
  145. \fn int starpu_pthread_mutex_lock(starpu_pthread_mutex_t *mutex)
  146. \ingroup API_Threads
  147. This function locks the given mutex. If the mutex is currently
  148. unlocked, it becomes locked and owned by the calling thread, and the
  149. function returns immediately. If the mutex is already locked by
  150. another thread, the function suspends the calling thread until the
  151. mutex is unlocked.
  152. This function also produces trace when the configure option \ref
  153. enable-fxt-lock "--enable-fxt-lock" is enabled.
  154. \fn int starpu_pthread_mutex_unlock(starpu_pthread_mutex_t *mutex)
  155. \ingroup API_Threads
  156. This function unlocks the given mutex. The mutex is assumed to be
  157. locked and owned by the calling thread on entrance to
  158. starpu_pthread_mutex_unlock().
  159. This function also produces trace when the configure option \ref
  160. enable-fxt-lock "--enable-fxt-lock" is enabled.
  161. \fn int starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex)
  162. \ingroup API_Threads
  163. This function behaves identically to starpu_pthread_mutex_lock(),
  164. except that it does not block the calling thread if the mutex is
  165. already locked by another thread (or by the calling thread in the case
  166. of a ``fast'' mutex). Instead, the function returns immediately with
  167. the error code EBUSY.
  168. This function also produces trace when the configure option \ref
  169. enable-fxt-lock "--enable-fxt-lock" is enabled.
  170. \typedef STARPU_PTHREAD_MUTEX_INITIALIZER
  171. \ingroup API_Threads
  172. This macro initializes the mutex given in parameter.
  173. \fn int starpu_pthread_key_create(starpu_pthread_key_t *key, void (*destr_function) (void *))
  174. \ingroup API_Threads
  175. This function allocates a new TSD key. The key is stored in the
  176. location pointed to by \p key.
  177. \fn int starpu_pthread_key_delete(starpu_pthread_key_t key)
  178. \ingroup API_Threads
  179. This function deallocates a TSD key. It does not check whether
  180. non-NULL values are associated with that key in the currently
  181. executing threads, nor call the destructor function associated with
  182. the key.
  183. \fn int starpu_pthread_setspecific(starpu_pthread_key_t key, const void *pointer)
  184. \ingroup API_Threads
  185. This function changes the value associated with \p key in the calling
  186. thread, storing the given \p pointer instead.
  187. \fn *starpu_pthread_getspecific(starpu_pthread_key_t key)
  188. \ingroup API_Threads
  189. This function returns the value associated with \p key on success, and
  190. NULL on error.
  191. \typedef STARPU_PTHREAD_COND_INITIALIZER
  192. \ingroup API_Threads
  193. This macro initializes the condition variable given in parameter.
  194. \fn starpu_pthread_cond_init(starpu_pthread_cond_t *cond, starpu_pthread_condattr_t *cond_attr)
  195. \ingroup API_Threads
  196. This function initializes the condition variable \p cond, using the
  197. condition attributes specified in \p cond_attr, or default attributes
  198. if \p cond_attr is NULL.
  199. \fn starpu_pthread_cond_signal(starpu_pthread_cond_t *cond)
  200. \ingroup API_Threads
  201. This function restarts one of the threads that are waiting on the
  202. condition variable \p cond. If no threads are waiting on \p cond,
  203. nothing happens. If several threads are waiting on \p cond, exactly
  204. one is restarted, but it not specified which.
  205. \fn starpu_pthread_cond_broadcast(starpu_pthread_cond_t *cond)
  206. \ingroup API_Threads
  207. This function restarts all the threads that are waiting on the
  208. condition variable \p cond. Nothing happens if no threads are waiting on cond.
  209. \fn starpu_pthread_cond_wait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex)
  210. \ingroup API_Threads
  211. This function atomically unlocks the mutex (as per
  212. starpu_pthread_mutex_unlock()) and waits for the condition variable \p cond
  213. to be signaled. The thread execution is suspended and does not consume
  214. any CPU time until the condition variable is signaled. The mutex must
  215. be locked by the calling thread on entrance to
  216. starpu_pthread_cond_wait(). Before returning to the calling thread, the
  217. function re-acquires mutex (as per starpu_pthread_mutex_lock()).
  218. This function also produces trace when the configure option \ref
  219. enable-fxt-lock "--enable-fxt-lock" is enabled.
  220. \fn starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex, const struct timespec *abstime)
  221. \ingroup API_Threads
  222. This function atomically unlocks \p mutex and waits on \p cond, as
  223. starpu_pthread_cond_wait() does, but it also bounds the duration of
  224. the wait.
  225. \fn starpu_pthread_cond_destroy(starpu_pthread_cond_t *cond)
  226. \ingroup API_Threads
  227. This function destroys a condition variable, freeing the resources it
  228. might hold. No threads must be waiting on the condition variable on
  229. entrance to the function.
  230. \fn starpu_pthread_rwlock_init(starpu_pthread_rwlock_t *rwlock, const starpu_pthread_rwlockattr_t *attr)
  231. \ingroup API_Threads
  232. This function is the same as starpu_pthread_mutex_init().
  233. \fn starpu_pthread_rwlock_destroy(starpu_pthread_rwlock_t *rwlock)
  234. \ingroup API_Threads
  235. This function is the same as starpu_pthread_mutex_destroy().
  236. \fn starpu_pthread_rwlock_rdlock(starpu_pthread_rwlock_t *rwlock)
  237. \ingroup API_Threads
  238. This function is the same as starpu_pthread_mutex_lock().
  239. \fn starpu_pthread_rwlock_wrlock(starpu_pthread_rwlock_t *rwlock)
  240. \ingroup API_Threads
  241. This function is the same as starpu_pthread_mutex_lock().
  242. \fn starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock)
  243. \ingroup API_Threads
  244. This function is the same as starpu_pthread_mutex_unlock().
  245. */