突然想起一个,我以前从 win32api 移植的 Event 类型,它的基本原理是两个变量:
class Event<T> {
public T result;
public Condition condition;
public void set(T t)
{ this.result = t; condition.notifyAll(); }
public T wait()
{ if (result == null) condition.wait(); return result; }
public void clear()
{ result = null; }
}
用这个辅助类型,你就可以在当前请求里面弄个 Event() 类型 wait() 挂在那里,把这个 Event 传给别的模块,他们处理它调用 set(result),你再继续处理请求。
【 在 climaxhell (anti) 的大作中提到: 】
: 接到请求 我只能做下面选择
: 1. 当前线程返回
: 2.起另一个线程池处理 返回一个callback
: ...................
--
FROM 112.47.122.*