qicosmos / rest_rpc

modern C++(C++11), simple, easy to use rpc framework
MIT License
1.66k stars 365 forks source link

Demo崩溃 #132

Closed huanglin2 closed 4 months ago

huanglin2 commented 4 months ago

connection.h 文件 write_queue_队列,在不同线程进行调用,未加锁 线程1: void response_interal(uint64_t req_id, std::shared_ptr data, request_type req_type = request_type::req_res) { assert(data->size() < MAX_BUF_LEN);

write_queue_.emplace_back(message_type{req_id, req_type, std::move(data)});
if (write_queue_.size() > 1) {
  return;
}

write();

} 线程2: void on_write(asio::error_code ec, std::size_t length) { if (ec) { print(ec); if (on_neterr) { (*on_neterr)(shared_from_this(), ec.message()); } close(false); return; }

if (has_closed()) {
  return;
}

write_queue_.pop_front();

if (!write_queue_.empty()) {
  write();
}

}

qicosmos commented 4 months ago

response_interal这个是内部的函数,内部会保证这个函数是单线程执行的,怎么会在外部多线程调用呢?有测试代码吗?

huanglin2 commented 4 months ago

response_interal这个是内部的函数,内部会保证这个函数是单线程执行的,怎么会在外部多线程调用呢?有测试代码吗?

项目工程demo test_callback();

qicosmos commented 4 months ago

请拉最新代码验证一下。

huanglin2 commented 4 months ago

没问题了