threads.doxy 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 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 SimGridSupport).
  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_exit(void *retval)
  115. \ingroup API_Threads
  116. This function terminates the calling thread and returns a value via
  117. \p retval that (if the thread is joinable) is available to another thread
  118. in the same process that calls starpu_pthread_join().
  119. \fn int starpu_pthread_attr_init(starpu_pthread_attr_t *attr)
  120. \ingroup API_Threads
  121. This function initializes the thread attributes object pointed to by
  122. \p attr with default attribute values.
  123. It does not do anything when the simulated performance mode is enabled
  124. (\ref SimGridSupport).
  125. \fn int starpu_pthread_attr_destroy(starpu_pthread_attr_t *attr)
  126. \ingroup API_Threads
  127. This function destroys a thread attributes object which is no longer
  128. required. Destroying a thread attributes object has no effect on
  129. threads that were created using that object.
  130. It does not do anything when the simulated performance mode is enabled
  131. (\ref SimGridSupport).
  132. \fn int starpu_pthread_attr_setdetachstate(starpu_pthread_attr_t *attr, int detachstate)
  133. \ingroup API_Threads
  134. This function sets the detach state attribute of the thread attributes
  135. object referred to by \p attr to the value specified in \p
  136. detachstate. The detach state attribute determines whether a thread
  137. created using the thread attributes object \p attr will be created in
  138. a joinable or a detached state.
  139. It does not do anything when the simulated performance mode is enabled
  140. (\ref SimGridSupport).
  141. \fn int starpu_pthread_mutex_init(starpu_pthread_mutex_t *mutex, const starpu_pthread_mutexattr_t *mutexattr)
  142. \ingroup API_Threads
  143. This function initializes the mutex object pointed to by \p mutex
  144. according to the mutex attributes specified in \p mutexattr. If \p
  145. mutexattr is NULL, default attributes are used instead.
  146. \fn int starpu_pthread_mutex_destroy(starpu_pthread_mutex_t *mutex)
  147. \ingroup API_Threads
  148. This function destroys a mutex object, freeing the resources it might
  149. hold. The mutex must be unlocked on entrance.
  150. \fn int starpu_pthread_mutex_lock(starpu_pthread_mutex_t *mutex)
  151. \ingroup API_Threads
  152. This function locks the given mutex. If the mutex is currently
  153. unlocked, it becomes locked and owned by the calling thread, and the
  154. function returns immediately. If the mutex is already locked by
  155. another thread, the function suspends the calling thread until the
  156. mutex is unlocked.
  157. This function also produces trace when the configure option \ref
  158. enable-fxt-lock "--enable-fxt-lock" is enabled.
  159. \fn int starpu_pthread_mutex_unlock(starpu_pthread_mutex_t *mutex)
  160. \ingroup API_Threads
  161. This function unlocks the given mutex. The mutex is assumed to be
  162. locked and owned by the calling thread on entrance to
  163. starpu_pthread_mutex_unlock().
  164. This function also produces trace when the configure option \ref
  165. enable-fxt-lock "--enable-fxt-lock" is enabled.
  166. \fn int starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex)
  167. \ingroup API_Threads
  168. This function behaves identically to starpu_pthread_mutex_lock(),
  169. except that it does not block the calling thread if the mutex is
  170. already locked by another thread (or by the calling thread in the case
  171. of a ``fast'' mutex). Instead, the function returns immediately with
  172. the error code EBUSY.
  173. This function also produces trace when the configure option \ref
  174. enable-fxt-lock "--enable-fxt-lock" is enabled.
  175. \typedef STARPU_PTHREAD_MUTEX_INITIALIZER
  176. \ingroup API_Threads
  177. This macro initializes the mutex given in parameter.
  178. \fn int starpu_pthread_mutexattr_gettype(const starpu_pthread_mutexattr_t *attr, int *type)
  179. \ingroup API_Threads
  180. todo
  181. \fn int starpu_pthread_mutexattr_settype(starpu_pthread_mutexattr_t *attr, int type)
  182. \ingroup API_Threads
  183. todo
  184. \fn int starpu_pthread_mutexattr_destroy(starpu_pthread_mutexattr_t *attr)
  185. \ingroup API_Threads
  186. todo
  187. \fn int starpu_pthread_mutexattr_init(starpu_pthread_mutexattr_t *attr)
  188. \ingroup API_Threads
  189. todo
  190. \fn int starpu_pthread_key_create(starpu_pthread_key_t *key, void (*destr_function) (void *))
  191. \ingroup API_Threads
  192. This function allocates a new TSD key. The key is stored in the
  193. location pointed to by \p key.
  194. \fn int starpu_pthread_key_delete(starpu_pthread_key_t key)
  195. \ingroup API_Threads
  196. This function deallocates a TSD key. It does not check whether
  197. non-NULL values are associated with that key in the currently
  198. executing threads, nor call the destructor function associated with
  199. the key.
  200. \fn int starpu_pthread_setspecific(starpu_pthread_key_t key, const void *pointer)
  201. \ingroup API_Threads
  202. This function changes the value associated with \p key in the calling
  203. thread, storing the given \p pointer instead.
  204. \fn *starpu_pthread_getspecific(starpu_pthread_key_t key)
  205. \ingroup API_Threads
  206. This function returns the value associated with \p key on success, and
  207. NULL on error.
  208. \typedef STARPU_PTHREAD_COND_INITIALIZER
  209. \ingroup API_Threads
  210. This macro initializes the condition variable given in parameter.
  211. \fn starpu_pthread_cond_init(starpu_pthread_cond_t *cond, starpu_pthread_condattr_t *cond_attr)
  212. \ingroup API_Threads
  213. This function initializes the condition variable \p cond, using the
  214. condition attributes specified in \p cond_attr, or default attributes
  215. if \p cond_attr is NULL.
  216. \fn starpu_pthread_cond_signal(starpu_pthread_cond_t *cond)
  217. \ingroup API_Threads
  218. This function restarts one of the threads that are waiting on the
  219. condition variable \p cond. If no threads are waiting on \p cond,
  220. nothing happens. If several threads are waiting on \p cond, exactly
  221. one is restarted, but it not specified which.
  222. \fn starpu_pthread_cond_broadcast(starpu_pthread_cond_t *cond)
  223. \ingroup API_Threads
  224. This function restarts all the threads that are waiting on the
  225. condition variable \p cond. Nothing happens if no threads are waiting on cond.
  226. \fn starpu_pthread_cond_wait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex)
  227. \ingroup API_Threads
  228. This function atomically unlocks the mutex (as per
  229. starpu_pthread_mutex_unlock()) and waits for the condition variable \p cond
  230. to be signaled. The thread execution is suspended and does not consume
  231. any CPU time until the condition variable is signaled. The mutex must
  232. be locked by the calling thread on entrance to
  233. starpu_pthread_cond_wait(). Before returning to the calling thread, the
  234. function re-acquires mutex (as per starpu_pthread_mutex_lock()).
  235. This function also produces trace when the configure option \ref
  236. enable-fxt-lock "--enable-fxt-lock" is enabled.
  237. \fn starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex, const struct timespec *abstime)
  238. \ingroup API_Threads
  239. This function atomically unlocks \p mutex and waits on \p cond, as
  240. starpu_pthread_cond_wait() does, but it also bounds the duration of
  241. the wait.
  242. \fn starpu_pthread_cond_destroy(starpu_pthread_cond_t *cond)
  243. \ingroup API_Threads
  244. This function destroys a condition variable, freeing the resources it
  245. might hold. No threads must be waiting on the condition variable on
  246. entrance to the function.
  247. \fn starpu_pthread_rwlock_init(starpu_pthread_rwlock_t *rwlock, const starpu_pthread_rwlockattr_t *attr)
  248. \ingroup API_Threads
  249. This function is the same as starpu_pthread_mutex_init().
  250. \fn starpu_pthread_rwlock_destroy(starpu_pthread_rwlock_t *rwlock)
  251. \ingroup API_Threads
  252. This function is the same as starpu_pthread_mutex_destroy().
  253. \fn starpu_pthread_rwlock_rdlock(starpu_pthread_rwlock_t *rwlock)
  254. \ingroup API_Threads
  255. This function is the same as starpu_pthread_mutex_lock().
  256. \fn int starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock)
  257. \ingroup API_Threads
  258. todo
  259. \fn starpu_pthread_rwlock_wrlock(starpu_pthread_rwlock_t *rwlock)
  260. \ingroup API_Threads
  261. This function is the same as starpu_pthread_mutex_lock().
  262. \fn int starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock)
  263. \ingroup API_Threads
  264. todo
  265. \fn starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock)
  266. \ingroup API_Threads
  267. This function is the same as starpu_pthread_mutex_unlock().
  268. \fn int starpu_pthread_barrier_init(starpu_pthread_barrier_t *barrier, const starpu_pthread_barrierattr_t *attr, unsigned count)
  269. \ingroup API_Threads
  270. todo
  271. \fn int starpu_pthread_barrier_destroy(starpu_pthread_barrier_t *barrier)
  272. \ingroup API_Threads
  273. todo
  274. \fn int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier)
  275. \ingroup API_Threads
  276. todo
  277. \fn int starpu_pthread_spin_init(starpu_pthread_spinlock_t *lock, int pshared)
  278. \ingroup API_Threads
  279. todo
  280. \fn int starpu_pthread_spin_destroy(starpu_pthread_spinlock_t *lock)
  281. \ingroup API_Threads
  282. todo
  283. \fn int starpu_pthread_spin_lock(starpu_pthread_spinlock_t *lock)
  284. \ingroup API_Threads
  285. todo
  286. \fn int starpu_pthread_spin_trylock(starpu_pthread_spinlock_t *lock)
  287. \ingroup API_Threads
  288. todo
  289. \fn int starpu_pthread_spin_unlock(starpu_pthread_spinlock_t *lock)
  290. \ingroup API_Threads
  291. todo
  292. */