我做了一个dbpool类,创建了一个线程池,每个线程开了一个mysql的链接,dbpool里面有请求队列,包括低级优先级查询队列,高级优先级查询队列。
那么问题来了,客户端登陆,然后服务器的业务线程提交了一个查询的sql到了dbpool的查询队列,业务层怎么等待数据库的返回?

解决方案 »

  1.   

    回调函数
    将查询的sql封装成结构
    Item{
       int weight
       string sql
       boost::function<....>  callback
    }把
    Item push到dbpool里面的请求队列
      

  2.   


    then how could get the result back? asynchronously? dbpool maintains a result message queue?business thread may have to be hung up in order to wait for the completion of the query. condition wait here?
      

  3.   

    那么放到线程池的队列中去等待执行了,但是如何返回数据呢?外面的线程等待? boost::function<....>  callback(resultset)需要池线程总数个 mutex