Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
ThreadPool::WeakQueue Class Reference

#include <threadpool.hh>

Collaboration diagram for ThreadPool::WeakQueue:
Collaboration graph

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
 
WeakQueueoperator= (const WeakQueue &)=delete
 
WeakQueueoperator= (WeakQueue &&)=delete
 
std::shared_ptr< Scroom::Detail::ThreadPool::QueueImplget ()
 

Static Public Member Functions

static Ptr create ()
 ThreadPool::WeakQueue.
 

Private Member Functions

 WeakQueue ()
 

Private Attributes

std::shared_ptr< Scroom::Detail::ThreadPool::QueueImplqi
 

Detailed Description

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.

See also
Queue

Member Typedef Documentation

◆ Ptr

using ThreadPool::WeakQueue::Ptr = std::shared_ptr<WeakQueue>

◆ WeakPtr

using ThreadPool::WeakQueue::WeakPtr = std::weak_ptr<WeakQueue>

Constructor & Destructor Documentation

◆ ~WeakQueue()

ThreadPool::WeakQueue::~WeakQueue ( )
default

◆ WeakQueue() [1/3]

ThreadPool::WeakQueue::WeakQueue ( const WeakQueue )
delete

◆ WeakQueue() [2/3]

ThreadPool::WeakQueue::WeakQueue ( WeakQueue &&  )
delete

◆ WeakQueue() [3/3]

ThreadPool::WeakQueue::WeakQueue ( )
private
403{
404}
static Ptr create()
QueueImpl.
Definition queue.cc:18
std::shared_ptr< Scroom::Detail::ThreadPool::QueueImpl > qi
Definition threadpool.hh:151

Member Function Documentation

◆ create()

ThreadPool::WeakQueue::Ptr ThreadPool::WeakQueue::create ( )
static

ThreadPool::WeakQueue.

Definition threadpool.hh:131
std::shared_ptr< WeakQueue > Ptr
Definition threadpool.hh:133

◆ get()

QueueImpl::Ptr ThreadPool::WeakQueue::get ( )
406{ return qi; }

◆ operator=() [1/2]

WeakQueue & ThreadPool::WeakQueue::operator= ( const WeakQueue )
delete

◆ operator=() [2/2]

WeakQueue & ThreadPool::WeakQueue::operator= ( WeakQueue &&  )
delete

Member Data Documentation

◆ qi

std::shared_ptr<Scroom::Detail::ThreadPool::QueueImpl> ThreadPool::WeakQueue::qi
private

The documentation for this class was generated from the following files: