fiber.qbk 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. [/
  2. (C) Copyright 2007-8 Anthony Williams.
  3. (C) Copyright 2011-12 Vicente J. Botet Escriba.
  4. (C) Copyright 2013 Oliver Kowalke.
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt).
  8. ]
  9. [section:fiber_mgmt Fiber management]
  10. [heading Synopsis]
  11. #include <boost/fiber/all.hpp>
  12. namespace boost {
  13. namespace fibers {
  14. class fiber;
  15. bool operator<( fiber const& l, fiber const& r) noexcept;
  16. void swap( fiber & l, fiber & r) noexcept;
  17. template< typename SchedAlgo, typename ... Args >
  18. void use_scheduling_algorithm( Args && ... args);
  19. bool has_ready_fibers();
  20. namespace algo {
  21. struct algorithm;
  22. template< typename PROPS >
  23. struct algorithm_with_properties;
  24. class round_robin;
  25. class shared_round_robin;
  26. }}
  27. namespace this_fiber {
  28. fibers::id get_id() noexcept;
  29. void yield();
  30. template< typename Clock, typename Duration >
  31. void sleep_until( std::chrono::time_point< Clock, Duration > const& abs_time)
  32. template< typename Rep, typename Period >
  33. void sleep_for( std::chrono::duration< Rep, Period > const& rel_time);
  34. template< typename PROPS >
  35. PROPS & properties();
  36. }
  37. [heading Tutorial]
  38. Each __fiber__ represents a micro-thread which will be launched and managed
  39. cooperatively by a scheduler. Objects of type __fiber__ are move-only.
  40. boost::fibers::fiber f1; // not-a-fiber
  41. void f() {
  42. boost::fibers::fiber f2( some_fn);
  43. f1 = std::move( f2); // f2 moved to f1
  44. }
  45. [heading Launching]
  46. A new fiber is launched by passing an object of a callable type that can be
  47. invoked with no parameters.
  48. If the object must not be copied or moved, then ['std::ref] can be used to
  49. pass in a reference to the function object. In this case, the user must ensure
  50. that the referenced object outlives the newly-created fiber.
  51. struct callable {
  52. void operator()();
  53. };
  54. boost::fibers::fiber copies_are_safe() {
  55. callable x;
  56. return boost::fibers::fiber( x);
  57. } // x is destroyed, but the newly-created fiber has a copy, so this is OK
  58. boost::fibers::fiber oops() {
  59. callable x;
  60. return boost::fibers::fiber( std::ref( x) );
  61. } // x is destroyed, but the newly-created fiber still has a reference
  62. // this leads to undefined behaviour
  63. The spawned __fiber__ does not immediately start running. It is enqueued in
  64. the list of ready-to-run fibers, and will run when the scheduler gets around
  65. to it.
  66. [#exceptions]
  67. [heading Exceptions]
  68. An exception escaping from the function or callable object passed to the __fiber__
  69. constructor calls `std::terminate()`.
  70. If you need to know which exception was thrown, use __future__ or
  71. __packaged_task__.
  72. [heading Detaching]
  73. A __fiber__ can be detached by explicitly invoking the __detach__ member
  74. function. After __detach__ is called on a fiber object, that object represents
  75. __not_a_fiber__. The fiber object may then safely be destroyed.
  76. boost::fibers::fiber( some_fn).detach();
  77. __boost_fiber__ provides a number of ways to wait for a running fiber to
  78. complete. You can coordinate even with a detached fiber using a [class_link
  79. mutex], or [class_link condition_variable], or any of the other [link
  80. synchronization synchronization objects] provided by the library.
  81. If a detached fiber is still running when the thread[s] main fiber terminates,
  82. the thread will not shut down.
  83. [heading Joining]
  84. In order to wait for a fiber to finish, the __join__ member function of the
  85. __fiber__ object can be used. __join__ will block until the __fiber__ object
  86. has completed.
  87. void some_fn() {
  88. ...
  89. }
  90. boost::fibers::fiber f( some_fn);
  91. ...
  92. f.join();
  93. If the fiber has already completed, then __join__ returns immediately and
  94. the joined __fiber__ object becomes __not_a_fiber__.
  95. [heading Destruction]
  96. When a __fiber__ object representing a valid execution context (the fiber is
  97. __joinable__) is destroyed, the program terminates. If you intend the fiber to
  98. outlive the __fiber__ object that launched it, use the __detach__ method.
  99. {
  100. boost::fibers::fiber f( some_fn);
  101. } // std::terminate() will be called
  102. {
  103. boost::fibers::fiber f(some_fn);
  104. f.detach();
  105. } // okay, program continues
  106. [#class_fiber_id]
  107. [heading Fiber IDs]
  108. Objects of class __fiber_id__ can be used to identify fibers. Each running
  109. __fiber__ has a unique __fiber_id__ obtainable from the corresponding __fiber__
  110. by calling the __get_id__ member function.
  111. Objects of class __fiber_id__ can be copied, and used as keys in associative
  112. containers: the full range of comparison operators is provided.
  113. They can also be written to an output stream using the stream insertion
  114. operator, though the output format is unspecified.
  115. Each instance of __fiber_id__ either refers to some fiber, or __not_a_fiber__.
  116. Instances that refer to __not_a_fiber__ compare equal to each other, but
  117. not equal to any instances that refer to an actual fiber. The comparison
  118. operators on __fiber_id__ yield a total order for every non-equal __fiber_id__.
  119. [#class_launch]
  120. [heading Enumeration `launch`]
  121. `launch` specifies whether control passes immediately into a
  122. newly-launched fiber.
  123. enum class launch {
  124. dispatch,
  125. post
  126. };
  127. [heading `dispatch`]
  128. [variablelist
  129. [[Effects:] [A fiber launched with `launch == dispatch` is entered
  130. immediately. In other words, launching a fiber with `dispatch` suspends the
  131. caller (the previously-running fiber) until the fiber scheduler has a chance
  132. to resume it later.]]
  133. ]
  134. [heading `post`]
  135. [variablelist
  136. [[Effects:] [A fiber launched with `launch == post` is passed to the
  137. fiber scheduler as ready, but it is not yet entered. The caller (the
  138. previously-running fiber) continues executing. The newly-launched fiber will
  139. be entered when the fiber scheduler has a chance to resume it later.]]
  140. [[Note:] [If `launch` is not explicitly specified, `post` is the default.]]
  141. ]
  142. [#class_fiber]
  143. [section:fiber Class `fiber`]
  144. #include <boost/fiber/fiber.hpp>
  145. namespace boost {
  146. namespace fibers {
  147. class fiber {
  148. public:
  149. class id;
  150. constexpr fiber() noexcept;
  151. template< typename Fn, typename ... Args >
  152. fiber( Fn &&, Args && ...);
  153. template< typename Fn, typename ... Args >
  154. fiber( ``[link class_launch `launch`]``, Fn &&, Args && ...);
  155. template< typename __StackAllocator__, typename Fn, typename ... Args >
  156. fiber( __allocator_arg_t__, StackAllocator &&, Fn &&, Args && ...);
  157. template< typename __StackAllocator__, typename Fn, typename ... Args >
  158. fiber( ``[link class_launch `launch`]``, __allocator_arg_t__, StackAllocator &&, Fn &&, Args && ...);
  159. ~fiber();
  160. fiber( fiber const&) = delete;
  161. fiber & operator=( fiber const&) = delete;
  162. fiber( fiber &&) noexcept;
  163. fiber & operator=( fiber &&) noexcept;
  164. void swap( fiber &) noexcept;
  165. bool joinable() const noexcept;
  166. id get_id() const noexcept;
  167. void detach();
  168. void join();
  169. template< typename PROPS >
  170. PROPS & properties();
  171. };
  172. bool operator<( fiber const&, fiber const&) noexcept;
  173. void swap( fiber &, fiber &) noexcept;
  174. template< typename SchedAlgo, typename ... Args >
  175. void use_scheduling_algorithm( Args && ...) noexcept;
  176. bool has_ready_fibers() noexcept;
  177. }}
  178. [heading Default constructor]
  179. constexpr fiber() noexcept;
  180. [variablelist
  181. [[Effects:] [Constructs a __fiber__ instance that refers to __not_a_fiber__.]]
  182. [[Postconditions:] [`this->get_id() == fiber::id()`]]
  183. [[Throws:] [Nothing]]
  184. ]
  185. [#fiber_fiber]
  186. [heading Constructor]
  187. template< typename Fn, typename ... Args >
  188. fiber( Fn && fn, Args && ... args);
  189. template< typename Fn, typename ... Args >
  190. fiber( ``[link class_launch `launch`]`` policy, Fn && fn, Args && ... args);
  191. template< typename __StackAllocator__, typename Fn, typename ... Args >
  192. fiber( __allocator_arg_t__, StackAllocator && salloc, Fn && fn, Args && ... args);
  193. template< typename __StackAllocator__, typename Fn, typename ... Args >
  194. fiber( ``[link class_launch `launch`]`` policy, __allocator_arg_t__, StackAllocator && salloc,
  195. Fn && fn, Args && ... args);
  196. [variablelist
  197. [[Preconditions:] [`Fn` must be copyable or movable.]]
  198. [[Effects:] [`fn` is copied or moved into internal storage for access by the
  199. new fiber. If [class_link launch] is specified (or defaulted) to
  200. `post`, the new fiber is marked ["ready] and will be entered at the next
  201. opportunity. If `launch` is specified as `dispatch`, the calling fiber
  202. is suspended and the new fiber is entered immediately.]]
  203. [[Postconditions:] [`*this` refers to the newly created fiber of execution.]]
  204. [[Throws:] [__fiber_error__ if an error occurs.]]
  205. [[Note:] [__StackAllocator__ is required to allocate a stack for the internal
  206. __econtext__. If `StackAllocator` is not explicitly passed, the default stack
  207. allocator depends on `BOOST_USE_SEGMENTED_STACKS`: if defined, you will get a
  208. __segmented_stack__, else a __fixedsize_stack__.]]
  209. [[See also:] [__allocator_arg_t__, [link stack Stack allocation]]]
  210. ]
  211. [heading Move constructor]
  212. fiber( fiber && other) noexcept;
  213. [variablelist
  214. [[Effects:] [Transfers ownership of the fiber managed by `other` to the newly
  215. constructed __fiber__ instance.]]
  216. [[Postconditions:] [`other.get_id() == fiber::id()` and `get_id()` returns the
  217. value of `other.get_id()` prior to the construction]]
  218. [[Throws:] [Nothing]]
  219. ]
  220. [heading Move assignment operator]
  221. fiber & operator=( fiber && other) noexcept;
  222. [variablelist
  223. [[Effects:] [Transfers ownership of the fiber managed by `other` (if any) to
  224. `*this`.]]
  225. [[Postconditions:] [`other->get_id() == fiber::id()` and `get_id()` returns the
  226. value of `other.get_id()` prior to the assignment.]]
  227. [[Throws:] [Nothing]]
  228. ]
  229. [heading Destructor]
  230. ~fiber();
  231. [variablelist
  232. [[Effects:] [If the fiber is __joinable__, calls std::terminate. Destroys
  233. `*this`.]]
  234. [[Note:] [The programmer must ensure that the destructor is never executed while
  235. the fiber is still __joinable__. Even if you know that the fiber has completed,
  236. you must still call either __join__ or __detach__ before destroying the `fiber`
  237. object.]]
  238. ]
  239. [member_heading fiber..joinable]
  240. bool joinable() const noexcept;
  241. [variablelist
  242. [[Returns:] [`true` if `*this` refers to a fiber of execution, which may or
  243. may not have completed; otherwise `false`.]]
  244. [[Throws:] [Nothing]]
  245. ]
  246. [member_heading fiber..join]
  247. void join();
  248. [variablelist
  249. [[Preconditions:] [the fiber is __joinable__.]]
  250. [[Effects:] [Waits for the referenced fiber of execution to complete.]]
  251. [[Postconditions:] [The fiber of execution referenced on entry has completed.
  252. `*this` no longer refers to any fiber of execution.]]
  253. [[Throws:] [`fiber_error`]]
  254. [[Error Conditions:] [
  255. [*resource_deadlock_would_occur]: if `this->get_id() == boost::this_fiber::get_id()`.
  256. [*invalid_argument]: if the fiber is not __joinable__.]]
  257. ]
  258. [member_heading fiber..detach]
  259. void detach();
  260. [variablelist
  261. [[Preconditions:] [the fiber is __joinable__.]]
  262. [[Effects:] [The fiber of execution becomes detached, and no longer has an
  263. associated __fiber__ object.]]
  264. [[Postconditions:] [`*this` no longer refers to any fiber of execution.]]
  265. [[Throws:] [`fiber_error`]]
  266. [[Error Conditions:] [
  267. [*invalid_argument]: if the fiber is not __joinable__.]]
  268. ]
  269. [member_heading fiber..get_id]
  270. fiber::id get_id() const noexcept;
  271. [variablelist
  272. [[Returns:] [If `*this` refers to a fiber of execution, an instance of
  273. __fiber_id__ that represents that fiber. Otherwise returns a
  274. default-constructed __fiber_id__.]]
  275. [[Throws:] [Nothing]]
  276. [[See also:] [[ns_function_link this_fiber..get_id]]]
  277. ]
  278. [template_member_heading fiber..properties]
  279. template< typename PROPS >
  280. PROPS & properties();
  281. [variablelist
  282. [[Preconditions:] [`*this` refers to a fiber of execution. [function_link
  283. use_scheduling_algorithm] has been called from this thread with a subclass of
  284. [template_link algorithm_with_properties] with the same template
  285. argument `PROPS`.]]
  286. [[Returns:] [a reference to the scheduler properties instance for `*this`.]]
  287. [[Throws:] [`std::bad_cast` if `use_scheduling_algorithm()` was called with a
  288. `algorithm_with_properties` subclass with some other template parameter
  289. than `PROPS`.]]
  290. [[Note:] [[template_link algorithm_with_properties] provides a way for a
  291. user-coded scheduler to associate extended properties, such as priority, with
  292. a fiber instance. This method allows access to those user-provided properties.]]
  293. [[See also:] [[link custom Customization]]]
  294. ]
  295. [member_heading fiber..swap]
  296. void swap( fiber & other) noexcept;
  297. [variablelist
  298. [[Effects:] [Exchanges the fiber of execution associated with `*this` and
  299. `other`, so `*this` becomes associated with the fiber formerly associated with
  300. `other`, and vice-versa.]]
  301. [[Postconditions:] [`this->get_id()` returns the same value as `other.get_id()`
  302. prior to the call. `other.get_id()` returns the same value as `this->get_id()`
  303. prior to the call.]]
  304. [[Throws:] [Nothing]]
  305. ]
  306. [function_heading_for swap..fiber]
  307. void swap( fiber & l, fiber & r) noexcept;
  308. [variablelist
  309. [[Effects:] [Same as `l.swap( r)`.]]
  310. [[Throws:] [Nothing]]
  311. ]
  312. [function_heading operator<]
  313. bool operator<( fiber const& l, fiber const& r) noexcept;
  314. [variablelist
  315. [[Returns:] [`true` if `l.get_id() < r.get_id()` is `true`, false otherwise.]]
  316. [[Throws:] [Nothing.]]
  317. ]
  318. [function_heading use_scheduling_algorithm]
  319. template< typename SchedAlgo, typename ... Args >
  320. void use_scheduling_algorithm( Args && ... args) noexcept;
  321. [variablelist
  322. [[Effects:] [Directs __boost_fiber__ to use `SchedAlgo`, which must be a
  323. concrete subclass of __algo__, as the scheduling algorithm for all fibers in
  324. the current thread. Pass any required `SchedAlgo` constructor arguments as
  325. `args`.]]
  326. [[Note:] [If you want a given thread to use a non-default scheduling
  327. algorithm, make that thread call `use_scheduling_algorithm()` before any other
  328. __boost_fiber__ entry point. If no scheduler has been set for the current
  329. thread by the time __boost_fiber__ needs to use it, the library will
  330. create a default [class_link round_robin] instance for this thread.]]
  331. [[Throws:] [Nothing]]
  332. [[See also:] [[link scheduling Scheduling], [link custom Customization]]]
  333. ]
  334. [function_heading has_ready_fibers]
  335. bool has_ready_fibers() noexcept;
  336. [variablelist
  337. [[Returns:] [`true` if scheduler has fibers ready to run.]]
  338. [[Throws:] [Nothing]]
  339. [[Note:] [Can be used for work-stealing to find an idle scheduler.]]
  340. ]
  341. [endsect] [/ section Class fiber]
  342. [#class_id]
  343. [section:id Class fiber::id]
  344. #include <boost/fiber/fiber.hpp>
  345. namespace boost {
  346. namespace fibers {
  347. class id {
  348. public:
  349. constexpr id() noexcept;
  350. bool operator==( id const&) const noexcept;
  351. bool operator!=( id const&) const noexcept;
  352. bool operator<( id const&) const noexcept;
  353. bool operator>( id const&) const noexcept;
  354. bool operator<=( id const&) const noexcept;
  355. bool operator>=( id const&) const noexcept;
  356. template< typename charT, class traitsT >
  357. friend std::basic_ostream< charT, traitsT > &
  358. operator<<( std::basic_ostream< charT, traitsT > &, id const&);
  359. };
  360. }}
  361. [heading Constructor]
  362. constexpr id() noexcept;
  363. [variablelist
  364. [[Effects:] [Represents an instance of __not_a_fiber__.]]
  365. [[Throws:] [Nothing.]]
  366. ]
  367. [operator_heading id..operator_equal..operator==]
  368. bool operator==( id const& other) const noexcept;
  369. [variablelist
  370. [[Returns:] [`true` if `*this` and `other` represent the same fiber,
  371. or both represent __not_a_fiber__, `false` otherwise.]]
  372. [[Throws:] [Nothing.]]
  373. ]
  374. [operator_heading id..operator_not_equal..operator!=]
  375. bool operator!=( id const& other) const noexcept;
  376. [variablelist
  377. [[Returns:] [[`! (other == * this)]]]
  378. [[Throws:] [Nothing.]]
  379. ]
  380. [operator_heading id..operator_less..operator<]
  381. bool operator<( id const& other) const noexcept;
  382. [variablelist
  383. [[Returns:] [`true` if `*this != other` is true and the
  384. implementation-defined total order of `fiber::id` values places `*this` before
  385. `other`, false otherwise.]]
  386. [[Throws:] [Nothing.]]
  387. ]
  388. [operator_heading id..operator_greater..operator>]
  389. bool operator>( id const& other) const noexcept;
  390. [variablelist
  391. [[Returns:] [`other < * this`]]
  392. [[Throws:] [Nothing.]]
  393. ]
  394. [operator_heading id..operator_less_equal..operator<=]
  395. bool operator<=( id const& other) const noexcept;
  396. [variablelist
  397. [[Returns:] [`! (other < * this)`]]
  398. [[Throws:] [Nothing.]]
  399. ]
  400. [operator_heading id..operator_greater_equal..operator>=]
  401. bool operator>=( id const& other) const noexcept;
  402. [variablelist
  403. [[Returns:] [`! (* this < other)`]]
  404. [[Throws:] [Nothing.]]
  405. ]
  406. [heading operator<<]
  407. template< typename charT, class traitsT >
  408. std::basic_ostream< charT, traitsT > &
  409. operator<<( std::basic_ostream< charT, traitsT > & os, id const& other);
  410. [variablelist
  411. [[Efects:] [Writes the representation of `other` to stream `os`. The
  412. representation is unspecified.]]
  413. [[Returns:] [`os`]]
  414. ]
  415. [endsect] [/ section Class fiber::id]
  416. [section:this_fiber Namespace this_fiber]
  417. In general, `this_fiber` operations may be called from the ["main] fiber
  418. [mdash] the fiber on which function `main()` is entered [mdash] as well as
  419. from an explicitly-launched thread[s] thread-function. That is, in many
  420. respects the main fiber on each thread can be treated like an
  421. explicitly-launched fiber.
  422. namespace boost {
  423. namespace this_fiber {
  424. fibers::fiber::id get_id() noexcept;
  425. void yield() noexcept;
  426. template< typename Clock, typename Duration >
  427. void sleep_until( std::chrono::time_point< Clock, Duration > const&);
  428. template< typename Rep, typename Period >
  429. void sleep_for( std::chrono::duration< Rep, Period > const&);
  430. template< typename PROPS >
  431. PROPS & properties();
  432. }}
  433. [ns_function_heading this_fiber..get_id]
  434. #include <boost/fiber/operations.hpp>
  435. namespace boost {
  436. namespace fibers {
  437. fiber::id get_id() noexcept;
  438. }}
  439. [variablelist
  440. [[Returns:] [An instance of __fiber_id__ that represents the currently
  441. executing fiber.]]
  442. [[Throws:] [Nothing.]]
  443. ]
  444. [ns_function_heading this_fiber..sleep_until]
  445. #include <boost/fiber/operations.hpp>
  446. namespace boost {
  447. namespace fibers {
  448. template< typename Clock, typename Duration >
  449. void sleep_until( std::chrono::time_point< Clock, Duration > const& abs_time);
  450. }}
  451. [variablelist
  452. [[Effects:] [Suspends the current fiber until the time point specified by
  453. `abs_time` has been reached.]]
  454. [[Throws:] [timeout-related exceptions.]]
  455. [[Note:] [The current fiber will not resume before `abs_time`, but there are no
  456. guarantees about how soon after `abs_time` it might resume.]]
  457. [[Note:] [["timeout-related exceptions] are as defined in the C++ Standard,
  458. section [*30.2.4 Timing specifications \[thread.req.timing\]]: ["A function
  459. that takes an argument which specifies a timeout will throw if, during its
  460. execution, a clock, time point, or time duration throws an exception. Such
  461. exceptions are referred to as ['timeout-related exceptions.]]]]
  462. ]
  463. [ns_function_heading this_fiber..sleep_for]
  464. #include <boost/fiber/operations.hpp>
  465. namespace boost {
  466. namespace fibers {
  467. template< class Rep, class Period >
  468. void sleep_for( std::chrono::duration< Rep, Period > const& rel_time);
  469. }}
  470. [variablelist
  471. [[Effects:] [Suspends the current fiber until the time duration specified by
  472. `rel_time` has elapsed.]]
  473. [[Throws:] [timeout-related exceptions.]]
  474. [[Note:][The current fiber will not resume before `rel_time` has elapsed, but
  475. there are no guarantees about how soon after that it might resume.]]
  476. ]
  477. [ns_function_heading this_fiber..yield]
  478. #include <boost/fiber/operations.hpp>
  479. namespace boost {
  480. namespace fibers {
  481. void yield() noexcept;
  482. }}
  483. [variablelist
  484. [[Effects:] [Relinquishes execution control, allowing other fibers to run.]]
  485. [[Throws:] [Nothing.]]
  486. [[Note:] [A fiber that calls
  487. `yield()` is not suspended: it is immediately passed to the scheduler as ready
  488. to run.]]
  489. ]
  490. [ns_function_heading this_fiber..properties]
  491. #include <boost/fiber/operations.hpp>
  492. namespace boost {
  493. namespace fibers {
  494. template< typename PROPS >
  495. PROPS & properties();
  496. }}
  497. [variablelist
  498. [[Preconditions:] [[function_link use_scheduling_algorithm] has been called
  499. from this thread with a subclass of [template_link
  500. algorithm_with_properties] with the same template argument `PROPS`.]]
  501. [[Returns:] [a reference to the scheduler properties instance for the
  502. currently running fiber.]]
  503. [[Throws:] [`std::bad_cast` if `use_scheduling_algorithm()` was called with an
  504. `algorithm_with_properties` subclass with some other template parameter
  505. than `PROPS`.]]
  506. [[Note:] [[template_link algorithm_with_properties] provides a way for a
  507. user-coded scheduler to associate extended properties, such as priority, with
  508. a fiber instance. This function allows access to those user-provided
  509. properties.]]
  510. [[Note:] [The first time this function is called from the main fiber of a
  511. thread, it may internally yield, permitting other fibers to run.]]
  512. [[See also:] [[link custom Customization]]]
  513. ]
  514. [endsect] [/ section Namespace this_fiber]
  515. [endsect] [/ section Fiber Management]