私はC++とboost :: thread_groupでスレッドプールを処理していますが、スレッド内でメソッド 'widgetProcessorJob'を呼び出してnullパラメータ(ウィジェット)を取得します。 私はさまざまな方法でそれを作ろうとしましたが、私はboost :: asioをひどく使っていると思います... 私は何が間違っているのかを教えてくれる誰かを探しています。boost :: thread_groupで呼び出されたメンバ関数のパラメータとして指定されたポインタがNULLです
void MarketingAutomation::processOnWidgets() {
boost::asio::io_service ioService;
boost::thread_group threadpool;
bool available = true; // need infinite loop in my program
int offset = 0; // Only for batching
boost::asio::io_service::work work(ioService);
for (int i = 0; i < _poolSize; i++) {
threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioService));
}
while (available) {
std::shared_ptr<sql::ResultSet> widgets(MyDBConnector::getInstance().getWidgets(_batchSize, offset)); // just getting some data from sql base with mysqlcppconn
if (!widgets->next()) {
offset = 0;
Logger::getInstance().logSTD("Restart widgets iteration !"); // this part is called when i did stuff on all batches
} else {
Logger::getInstance().logSTD("Proccess on " + std::to_string((offset/_batchSize) + 1) + " batch");
// loop through the batch
while (!widgets->isAfterLast()) {
ioService.post(boost::bind(&MarketingAutomation::widgetProcessorJob, this, widgets));
widgets->next();
}
threadpool.join_all();
Logger::getInstance().logSTD("Finish on " + std::to_string((offset/_batchSize) + 1) + " batch");
offset += _batchSize;
}
}
}
// Here is the function called in thread
void MarketingAutomation::widgetProcessorJob(std::shared_ptr<sql::ResultSet> widget) {
WidgetProcessor widgetProcessor(widget, _kind); // Here widget is already null, but why ? :'(
widgetProcessor.processOnWidget();
}
こんにちはのDraxおかげで、あなたの返信のためにたくさん、あなたは幸いにも、奇妙な行動にプログラムを駆動しますが可能性がミスを指して、私はこの結果セットに書いたことはありません!しかし、私は最終的に何が間違っているかを見つけ、数時間または数分で正解を投稿します。 –