- Attention
- This class belongs to module ALib ThreadModel, which is not in a stable and consistent state, yet. Also this type is considered experimental.
Defines jobs which are scheduled with instances of types ThreadPool and DedicatedWorker.
The type is virtual and designed to be the base type for custom "jobs". It holds a job-ID of type std::type_info
which is used to identify the job type with processing. This ID usually represents - but does not need to! - the derived type. By including the ID into the job, one derived job-type object can be used with different job definitions. For example, built-in derived type JPromise may be used as the "shared data" between the sender and the processing thread. The constructor of JPromise accepts a type ID to store.
This explains that class Job has two main aspects:
- Provide information to a worker thread about what is to be done.
- Provide shared data between the sender and the worker.
Instances of this class are always pool-allocated. Allocation, construction, destruction and deletion are always under the control of either type ThreadPool or DedicatedWorker. Pool allocation requires passing the object size with deletion (all details on this topic is found here). For this, derived types that add new field members have to override method SizeOf in a way described with the documentation of that virtual method, to return the correct size of the derived type.
Virtual method Do has to be overridden in case a job is to be scheduled with class ThreadPool. In case a derived type is (exclusively) used with type DedicatedWorker, it is up to the user of this module whether method Do is implemented or not. If not, then a custom type derived from DedicatedWorker has to override method process and handle the job type there.
- See also
- The Programmer's Manual of this module ALib ThreadModel for detailed information.
Definition at line 71 of file jobs.hpp.
virtual void PrepareDeferredDeletion |
( |
| ) |
|
|
inlinevirtual |
This method is called by the worker thread in the case this job was scheduled for deferred deletion using ThreadPool::DeleteJobDeferred or DedicatedWorker::DeleteJobDeferred. The method is intended to prepare the deletion of this job without further actions that the sender of a job otherwise would perform.
Overriding this method must be considered well. It is up to the contract between the caller and the implementation of a custom worker, how to handle this situation.
As a sample, within the implementation of this module, it is used with class JPromise to disable the warnings of deleting an unfulfilled and un-awaited promise in debug-compilations.
- Note
- This method is called by the worker thread, so it is not allowed to be called by any other methods of the worker or caller
Reimplemented in JPromise.
Definition at line 101 of file jobs.hpp.