2 * Copyright (c) 2005, Eric Crahen
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is furnished
9 * to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __ZTEXECUTOR_H__
24 #define __ZTEXECUTOR_H__
26 #include "zthread/Thread.h"
27 #include "zthread/Waitable.h"
35 * @author Eric Crahen <http://www.code-foo.com>
36 * @date <2003-07-16T22:39:39-0400>
39 * Execeutors are an implementation of the Executor pattern. This is
40 * a more versatile construct than a thread pool. A paper describing can
41 * be found in the proceedings of the 2002 VikingPLOP conference.
45 * - <em>execute</em>()ing task with an Executor will submit the task, scheduling
46 * it for execution at some future time depending on the Executor being used.
50 * - <em>cancel</em>()ing an Executor will cause it to stop accepting
55 * - <em>interrupt</em>()ing an Executor will cause the any thread running
56 * a task which was submitted prior to the invocation of this function to
57 * be interrupted during the execution of that task.
61 * - <em>wait</em>()ing on a PoolExecutor will block the calling thread
62 * until all tasks that were submitted prior to the invocation of this function
68 class Executor
: public Cancelable
, public Waitable
, private NonCopyable
{
72 * If supported by the Executor, interrupt all tasks submitted prior to
73 * the invocation of this function.
75 virtual void interrupt() = 0;
78 * Submit a task to this Executor.
80 * @param task Task to be run by a thread managed by this executor
82 * @pre The Executor should have been canceled prior to this invocation.
83 * @post The submitted task will be run at some point in the future by this Executor.
85 * @exception Cancellation_Exception thrown if the Executor was canceled prior to
86 * the invocation of this function.
88 virtual void execute(const Task
& task
) = 0;
92 } // namespace ZThread
94 #endif // __ZTEXECUTOR_H__