主题:[原创]有谁用过ACE的ACE_Future吗,谁能说明为什么它的set功能限制使用一次吗
有谁用过ACE的ACE_Future吗,谁能说明为什么它的set功能限制使用一次吗? Tks
template <class T> int
ACE_Future_Rep<T>::set (const T &r,
ACE_Future<T> &caller)
{
// If the value is already produced, ignore it...
if (this->value_ == 0)
{
ACE_GUARD_RETURN (ACE_SYNCH_RECURSIVE_MUTEX,
ace_mon,
this->value_ready_mutex_,
-1);
// Otherwise, create a new result value. Note the use of the
// Double-checked locking pattern to avoid multiple allocations.
if (this->value_ == 0) // Still no value, so proceed
{
ACE_NEW_RETURN (this->value_,
T (r),
-1);
// Remove and notify all subscribed observers.
typename OBSERVER_COLLECTION::iterator iterator =
this->observer_collection_.begin ();
typename OBSERVER_COLLECTION::iterator end =
this->observer_collection_.end ();
while (iterator != end)
{
OBSERVER *observer = *iterator++;
observer->update (caller);
}
// Signal all the waiting threads.
return this->value_ready_.broadcast ();
}
// Destructor releases the lock.
}
return 0;
template <class T> int
ACE_Future_Rep<T>::set (const T &r,
ACE_Future<T> &caller)
{
// If the value is already produced, ignore it...
if (this->value_ == 0)
{
ACE_GUARD_RETURN (ACE_SYNCH_RECURSIVE_MUTEX,
ace_mon,
this->value_ready_mutex_,
-1);
// Otherwise, create a new result value. Note the use of the
// Double-checked locking pattern to avoid multiple allocations.
if (this->value_ == 0) // Still no value, so proceed
{
ACE_NEW_RETURN (this->value_,
T (r),
-1);
// Remove and notify all subscribed observers.
typename OBSERVER_COLLECTION::iterator iterator =
this->observer_collection_.begin ();
typename OBSERVER_COLLECTION::iterator end =
this->observer_collection_.end ();
while (iterator != end)
{
OBSERVER *observer = *iterator++;
observer->update (caller);
}
// Signal all the waiting threads.
return this->value_ready_.broadcast ();
}
// Destructor releases the lock.
}
return 0;