-
首页
-
C4D R23.110 C++ SDK
JobQueueInterface Class Reference
线程
#include <jobqueue.h>
详细描述
A JobQueue is used to enqueue and execute jobs. You can specify the priority and the number of its worker threads when calling Init().
Besides multithreading a nice application of the queues is to use them to serialize jobs, e.g. if your multithreaded code has to write results to a non-threadsafe part of the application you do this by creating a queue with just one thread that serializes the write request (this is similar to what happens when you enqueue a job in the main event queue).
Please note that you have to make sure that a queue has executed all jobs before releasing it (the queue can not check that because right after such a check a running dequeued job might enqueue something while the queue would try to delete itself). One way to ensure this is to wait for a master job or group which enqueues all depending groups and jobs. @MAXON_ANNOTATION{refclass=false}
成员函数文档编制
◆
MAXON_INTERFACE_NONVIRTUAL()
◆
Alloc()
Creates and initializes a job queue. Do not request more threads than CPU cores are available (use JOBQUEUE_USEMAXIMUMTHREADS to request the maximum thread count or
Application::GetMachineInfo()
to get that information).
-
参数
-
[in]
|
allocLocation
|
Source location.
|
[in]
|
type
|
Queue
type.
|
[in]
|
threadCnt
|
The number of threads used by the queue.
|
[in]
|
mode
|
Scheduling options for the queue. Most of the time there's no need to specify something else than
JOBQUEUEMODE::DEFAULT
.
|
[in]
|
name
|
The queue name.
|
[out]
|
ownerId
|
Used to return the optional owner id of the queue (can be used for CancelAndWait).
|
◆
GetThreadCount()
[1/2]
Returns the number of threads used for the queue. THREADSAFE.
-
返回
-
Number of threads.
◆
GetThreadCount()
[2/2]
Returns the number of threads to be used. THREADSAFE.
-
参数
-
[in]
|
queue
|
Queue
interface pointer or JOBQUEUE_CURRENT, JOBQUEUE_NONE.
|
[in]
|
maxWaitSessionLevel
|
Private: Maximum number of nested Wait() calls.
|
-
返回
-
Number of threads. Guaranteed to be >= 1 (even for JOBQUEUE_NONE).
◆
Cancel()
Cancels execution of all jobs in the queue (including jobs which are enqueued after this call). Usually the next step is to release the queue and free all its resources. Only the owner of a queue can cancel it (requires the id returned by Init()). As usual
Cancel()
will not wait and returns immediately after the cancel condition has been set. THREADSAFE.
-
参数
-
[in]
|
ownerId
|
Owner id of the queue (only the owner is allowed to cancel a queue).
|
◆
CancelAndWait()
Cancels execution of all jobs in the queue (including jobs which are enqueued after this call). Waits until the currently running jobs have finished. Only the owner of a queue can cancel it (requires the id returned by Init()). THREADSAFE.
-
参数
-
[in]
|
ownerId
|
Owner id of the queue (only the owner is allowed to cancel a queue).
|
◆
EnableThreadAffinity()
Enables support for job groups with thread affinity. Only the owner of a queue can enable thread affinity (requires the id returned by Init()). THREADSAFE.
-
参数
-
[in]
|
ownerId
|
Owner id of the queue.
|
◆
GetDestinationQueue()
Returns the queue being used when you specify JOBQUEUE_CURRENT. Usually the destination queue is the same as the queue of the current thread, but there are exceptions: The main (UI) thread for example belongs to the main thread queue (returned by
GetMainThreadQueue()
), but it has the default queue as target if you specify JOBQUEUE_CURRENT. Furthermore there are rare cases (backward compatibility) where the destination queue has been modified using
SetDestinationQueue()
. THREADSAFE.
-
返回
-
Destination queue (guaranteed to be a valid pointer).
◆
SetDestinationQueue()
Changes the queue that will be used when you enqueue a job/group from this thread and specify JOBQUEUE_CURRENT. All threads created by the caller from now on will inherit the queue.
You must own the thread to call this method. Since all child threads will own the the queue you must make sure it'll be referenced for the whole life time of these threads. Removing a reference before these child threads have finished can result in a crash because the threads will not own the queue or add a reference to it.
If you have made sure the queue is not used anymore you can call
SetDestinationQueue()
and switch back to the previous destination queue.
Calling this method from within a job or group will result in an error.
-
参数
-
[in]
|
queue
|
The queue to be used as JOBQUEUE_CURRENT.
|
-
返回
-
OK on success.
◆
GetMainThreadQueue()
Returns the main thread job queue. If you want to run a job in the main thread's context you can enqueue it specifying this queue. Jobs in the main thread queue will be executed whenever the main thread checks for events. This means execution of a job might be delayed if somebody performs a long blocking polling loop. THREADSAFE.
-
返回
-
Main thread job queue (guaranteed to be a valid pointer).
◆
GetServiceIOQueue()
Returns a queue for asynchronous I/O and service jobs. THREADSAFE.
-
返回
-
Service I/O queue (guaranteed to be a valid pointer).