|
Scroom 0.14-49-gb7ae7a6d
|
#include <threadpool.hh>

Public Types | |
| using | Ptr = std::shared_ptr< WeakQueue > |
| using | WeakPtr = std::weak_ptr< WeakQueue > |
Public Member Functions | |
| ~WeakQueue ()=default | |
| WeakQueue (const WeakQueue &)=delete | |
| WeakQueue (WeakQueue &&)=delete | |
| WeakQueue & | operator= (const WeakQueue &)=delete |
| WeakQueue & | operator= (WeakQueue &&)=delete |
| std::shared_ptr< Scroom::Detail::ThreadPool::QueueImpl > | get () |
Static Public Member Functions | |
| static Ptr | create () |
| ThreadPool::WeakQueue. | |
Private Member Functions | |
| WeakQueue () | |
Private Attributes | |
| std::shared_ptr< Scroom::Detail::ThreadPool::QueueImpl > | qi |
Represent a weak Queue reference ThreadPool.
On occasion, you want tasks that are running on the ThreadPool to reschedule themselves. However, if tasks have a reference to their queue, you might risk a deadlock. If a tasks holds the last reference to the queue, then on task destruction, the queue will be destroyed. However, destroying the queue blocks for the task to finish.
As a way out of this, we introduce the WeakQueue, which can be used to schedule tasks, but does not contribute towards keeping the queue alive. I.e. If you destroy the last reference to a Queue, you can still use the associated WeakQueue to schedule tasks, but they will no longer be executed, because the Queue no longer exists.
| using ThreadPool::WeakQueue::Ptr = std::shared_ptr<WeakQueue> |
| using ThreadPool::WeakQueue::WeakPtr = std::weak_ptr<WeakQueue> |
|
default |
|
delete |
|
delete |
|
private |
|
static |
| QueueImpl::Ptr ThreadPool::WeakQueue::get | ( | ) |
|
private |