mirror of
https://github.com/boostorg/fiber.git
synced 2026-02-20 14:42:21 +00:00
tasklet-docu spin_* removed
This commit is contained in:
@@ -1,163 +0,0 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:spin_conditions Spinning Condition Variables]
|
||||
|
||||
[heading Synopsis]
|
||||
|
||||
The class `condition` provides a mechanism for one tasklet to wait for
|
||||
notification `condition`. When the tasklet is woken from the wait, then it
|
||||
checks to see if the appropriate condition is now true, and continues if so. If
|
||||
the condition is not true, then the tasklet then calls `wait` again to resume
|
||||
waiting. In the simplest case, this condition is just a boolean variable:
|
||||
|
||||
boost::tasklets::condition cond;
|
||||
boost::tasklets::mutex mtx;
|
||||
bool data_ready;
|
||||
|
||||
void process_data();
|
||||
|
||||
void wait_for_data_to_process()
|
||||
{
|
||||
boost::unique_lock< boost::tasklets::mutex > lk( mtx);
|
||||
while ( ! data_ready)
|
||||
{
|
||||
cond.wait( lk);
|
||||
}
|
||||
process_data();
|
||||
}
|
||||
|
||||
Notice that the `lk` is passed to `wait`: `wait` will atomically add the tasklet
|
||||
to the set of tasklets waiting on the condition variable, and unlock the mutex.
|
||||
When the tasklet is woken, the mutex will be locked again before the call to
|
||||
`wait` returns. This allows other tasklets to acquire the mutex in order to
|
||||
update the shared data, and ensures that the data associated with the condition
|
||||
is correctly synchronized.
|
||||
|
||||
In the mean time, another tasklet sets the condition to `true`, and then calls
|
||||
either `notify_one` or `notify_all` on the condition variable to wake one
|
||||
waiting tasklet or all the waiting tasklets respectively.
|
||||
|
||||
void retrieve_data();
|
||||
void prepare_data();
|
||||
|
||||
void prepare_data_for_processing()
|
||||
{
|
||||
retrieve_data();
|
||||
prepare_data();
|
||||
{
|
||||
boost::lock_guard< boost::tasklets::mutex > lk( mtx);
|
||||
data_ready = true;
|
||||
}
|
||||
cond.notify_one();
|
||||
}
|
||||
|
||||
Note that the same mutex is locked before the shared data is updated, but that
|
||||
the mutex does not have to be locked across the call to `notify_one`.
|
||||
|
||||
[section:condition Class `condition`]
|
||||
|
||||
#include <boost/tasklet/condition.hpp>
|
||||
|
||||
class condition
|
||||
{
|
||||
public:
|
||||
void notify_one();
|
||||
void notify_all();
|
||||
|
||||
void wait( boost::unique_lock< boost::tasklets::mutex > & lk);
|
||||
|
||||
template< typename Pred >
|
||||
void wait( boost::unique_lock< boost::tasklets::mutex > & lk, Pred pred);
|
||||
|
||||
template< typename LockType >
|
||||
void wait( LockType & lk);
|
||||
|
||||
template< typename LockType, typename Pred >
|
||||
void wait( LockType & lk, Pred predicate);
|
||||
};
|
||||
|
||||
[section:notify_one `void notify_one()`]
|
||||
[variablelist
|
||||
[[Effects:] [If any tasklets are currently __blocked__ waiting on `*this` in a
|
||||
call to `wait`, unblocks one of those tasklets.]]
|
||||
[[Throws:] [Nothing.]]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[section:notify_all `void notify_all()`]
|
||||
[variablelist
|
||||
[[Effects:] [If any tasklets are currently __blocked__ waiting on `*this` in a
|
||||
call to `wait`, unblocks all of those tasklets.]]
|
||||
[[Throws:] [Nothing.]]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[section:wait `void wait( boost::unique_lock< boost::tasklets::mutex > & lk)`]
|
||||
[variablelist
|
||||
[[Precondition:] [`lk` is locked by the current tasklet, and either no other
|
||||
tasklet is currently waiting on `*this`, or the execution of the `mutex()`
|
||||
member function on the `lk` objects supplied in the calls to `wait` in all the
|
||||
tasklets currently waiting on `*this` would return the same value as
|
||||
`lk->mutex()` for this call to `wait`.]]
|
||||
[[Effects:] [Atomically call `lk.unlock()` and blocks the current tasklet. The
|
||||
tasklet will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, or spuriously. When the tasklet is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lk.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lk.lock()` if the
|
||||
function exits with an exception.]]
|
||||
[[Postcondition:] [`lk` is locked by the current tasklet.]]
|
||||
[[Throws:] [__tasklet_error__ if an error
|
||||
occurs. __tasklet_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __tasklet__ object associated with the current tasklet of
|
||||
execution.]]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[section:wait_predicate `template< typename Pred > void wait( boost::unique_lock< boost::tasklets::mutex > & lk, Pred pred)`]
|
||||
[variablelist
|
||||
[[Effects:] [As-if ``
|
||||
while ( ! pred())
|
||||
{
|
||||
wait( lk);
|
||||
}
|
||||
``]]
|
||||
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[section:wait_t `template< typename LockType > void wait( LockType & lk)`]
|
||||
[variablelist
|
||||
[[Effects:] [Atomically call `lk.unlock()` and blocks the current tasklet. The
|
||||
tasklet will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, or spuriously. When the tasklet is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lk.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lk.lock()` if the
|
||||
function exits with an exception.]]
|
||||
[[Postcondition:] [`lk` is locked by the current tasklet.]]
|
||||
[[Throws:] [__tasklet_error__ if an error
|
||||
occurs. __tasklet_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __tasklet__ object associated with the current tasklet of
|
||||
execution.]]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[section:wait_predicate_t `template< typename LockType, typename Pred > void wait( LockType & lk, Pred pred)`]
|
||||
[variablelist
|
||||
[[Effects:] [As-if ``
|
||||
while ( ! pred())
|
||||
{
|
||||
wait( lock);
|
||||
}
|
||||
``]]
|
||||
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
@@ -1,38 +0,0 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:spin_mutex_types Spinning Mutex Types]
|
||||
|
||||
[section:spin_mutex Class `spin_mutex`]
|
||||
|
||||
#include <boost/tasklets/mutex.hpp>
|
||||
|
||||
class spin_mutex : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
spin_mutex();
|
||||
|
||||
~spin_mutex();
|
||||
|
||||
void lock();
|
||||
bool try_lock();
|
||||
void unlock();
|
||||
|
||||
typedef unique_lock< spin_mutex > scoped_lock;
|
||||
};
|
||||
|
||||
__spin_mutex__ implements the __lockable_concept__ to provide an
|
||||
exclusive-ownership mutex. At most one tasklet can own the lock on a given
|
||||
instance of __mutex__ at any time. Multiple concurrent calls to __lock__,
|
||||
__try_lock__ and __unlock__ shall be permitted.
|
||||
|
||||
The tasklets and threads blocked in __lock__ are spin waiting until the lock get
|
||||
released, e.g. try to get an calling __tasklet_yield__/__thread_yield__.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
Reference in New Issue
Block a user