1

ゲーム サーバー用のスレッド プールを作成しましたが、コンパイル中に 1 つのエラーが発生し、修正方法がわかりませんでした。

エラー :

Connection/CConnection.cpp: ラムダ関数: Connection/CConnection.cpp:62:6: エラー: 'this' は、このラムダ関数に対してキャプチャされませんでした

スレッドプール宣言:

class Worker {
public:
    Worker(ThreadPool &s) : pool(s) { }
    void operator()();
private:
    ThreadPool &pool; 
};

// the actual thread pool
class ThreadPool {
public:
    ThreadPool(size_t);
    template<class F>
    void enqueue(F f);
    ~ThreadPool();
private:
    // need to keep track of threads so we can join them
    std::vector< std::unique_ptr<boost::thread> > workers;

    // the io_service we are wrapping
    boost::asio::io_service service;
    boost::asio::io_service::work working;
    friend class Worker;
};

template<class F>
void ThreadPool::enqueue(F f)
{
    service.post(f);
}

それを使用する機能:

void CConnection::handle()
{
     int i = 0;
     ThreadPool pool(4);
     pool.enqueue([i]
    {
     char * databuffer;
     databuffer = new char[16];
     for(int i = 0;i<16;i++)
     {
      databuffer[i] = 0x00;
     }
     databuffer[0] = 16;
     databuffer[4] = 1;
     databuffer[8] = 1;
     databuffer[12] = 1;
     asynchronousSend(databuffer, 16);
    });
}

誰かがどこにいて、何が問題なのか教えてもらえますか?

4

1 に答える 1