Multithreading 设计模式的名称,其中类的唯一任务只是确保执行前置条件和后置条件任务
我有一个类,我确切地知道它需要做什么,但我想不出一个名称来描述它在做什么 我需要管理名为TransformThread的类的行为。它表示具有执行循环的线程,执行循环将任务从消息队列中分解出来 我需要确保在提交一批任务后,父线程在离开作用域之前等待TransformThread在某些共享对象上获得读取锁定。在子线程启动之前,主线程不能离开作用域 我的解决方案是创建TransformThread的子类Multithreading 设计模式的名称,其中类的唯一任务只是确保执行前置条件和后置条件任务,multithreading,design-patterns,Multithreading,Design Patterns,我有一个类,我确切地知道它需要做什么,但我想不出一个名称来描述它在做什么 我需要管理名为TransformThread的类的行为。它表示具有执行循环的线程,执行循环将任务从消息队列中分解出来 我需要确保在提交一批任务后,父线程在离开作用域之前等待TransformThread在某些共享对象上获得读取锁定。在子线程启动之前,主线程不能离开作用域 我的解决方案是创建TransformThread的子类 class TransformThread { class LockHelper {
class TransformThread {
class LockHelper {
TransformThread & _parent;
// Tells the transform thread to start trying to get that read lock.
LockHelper(TransformThread & parent);
// Blocks main thread until the transform thread has its read lock.
~LockHelper();
// Add a task to the threadsafe TransformThread queue.
// This will be the only way to add tasks to a TransformThread since I don't want people adding tasks without afterwards blocking until the read lock is acquired.
AddTransform (TransformTask const & foo);
};
LockHelper GetLockHelper () { return LockHelper(*this); }
};
LockHelper是个可怕的名字我该怎么称呼它呢?这样,其他程序员就可以看到正在使用的类,并知道它在做什么,而不必深入标题?打开它,您可能会更幸运,这似乎有点离题了。为了提供一些有建设性的东西。。观察者嗯,不,对观察者/可观察者的影响太大了。执法者?