threads.doxy 13 KB

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