threads.doxy 13 KB

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