代码之家  ›  专栏  ›  技术社区  ›  CodingWithoutComments

什么时候多线程不是一个好主意?[关闭]

  •  25
  • CodingWithoutComments  · 技术社区  · 16 年前

    我最近正在开发一个通过以太网和串行网络发送和接收消息的应用程序。然后我被派去 添加 DIO离散体的监控。我想,

    “没有理由中断主机 消息中涉及的线程 正在处理,我将创建 另一个线程 监控迪奥。”

    然而,这一决定被证明是 贫穷的 . 有时主线程会在发送和接收串行消息之间中断。这种干扰会扰乱时间安排,唉,消息会丢失(永远)。

    我找到了另一种监控DIO的方法 不使用其他线程 以太网和串行通信恢复到正确的功能。

    然而,整个惨败让我想起来。 他们对什么时候 使用多个线程和/或任何人在使用多个线程时是否有更多的情况示例不是一个好主意?

    **编辑:根据您的评论,在浏览互联网获取信息后,我撰写了一篇题为 When is multi-threading not a good idea?

    14 回复  |  直到 16 年前
        1
  •  14
  •   cdeszaq Sudhir N    13 年前

        2
  •  6
  •   Thomee    16 年前

        3
  •  6
  •   Adam Liss    16 年前
        4
  •  4
  •   Bite code    16 年前

        5
  •  3
  •   harningt    16 年前

    The C10K problem

    Per CPU [*] EVENTLOOP   ------ Handles nonblocking I/O using OS/library utilities
                           |                        \___  Threadpool for various blocking events
                           Threadpool for handling the I/O messages that would take long
    
        6
  •  2
  •   Michael Pliskin    16 年前

        7
  •  2
  •   larsivi    16 年前

        8
  •  2
  •   community wiki SingleNegationElimination    15 年前

        9
  •  1
  •   Claus Thomsen    16 年前

        10
  •  1
  •   finnw    16 年前

        11
  •  1
  •   Jon Cage    16 年前
        12
  •  0
  •   oglester    16 年前

        13
  •  0
  •   Todd Stout    15 年前
        14
  •  0
  •   Kieveli    15 年前