threads.doxy 14 KB

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