跳转至

ev-vroom-semaphore-released-002

字段 值
项目 VROOM-Project/vroom
固定 commit 43dd7d0b8b56
路径 src/structures/vroom/input/input.cpp
行段 L1264-L1274
特性 闩锁、屏障与计数信号量
许可证 BSD-2-Clause
代码来源 项目源码
级别 manual
审核 zyuhao7 @ 2026-10-27
测试代码 否
发现方式 manual

用法

为路由请求创建信号量,获取许可后再调用外部路由服务

为什么典型

外部 HTTP 路由服务有并发上限,信号量把配额限制从线程数量解耦出来。

摘录

  if (_geometry) {
    std::vector<std::jthread> threads;
    threads.reserve(sol.routes.size());
    std::exception_ptr ep = nullptr;
    std::mutex ep_m;
    std::counting_semaphore<MAX_ROUTING_THREADS> semaphore(
      std::min(MAX_ROUTING_THREADS, nb_thread));

    auto run_routing = [this, &semaphore, &sol, &ep, &ep_m](std::size_t i) {
      semaphore.acquire();
      try {

备注

生产路径;每个 route 线程先 acquire,调用完成或抛异常后 release。

查看固定 commit 源码 · 返回证据索引