【问题标题】:How to tell which pthread wakes up the pthread? C如何判断哪个 pthread 唤醒了 pthread? C
【发布时间】:2018-04-19 09:19:57
【问题描述】:

我目前正在从事多线程编程。我有几个客户 pthread 和两个职员 pthread(A 和 B)。每个客户 pthread 都有一个唯一的 id、arrival_time 和 service_time。客户 pthread 最初处于休眠状态,并等待由职员线程唤醒。我的问题是如何找到每个客户线程被职员 pthread A 或职员 pthread B 唤醒?

谢谢

【问题讨论】:

  • 只使用一个消息队列,并且有消息包含职员ID?不看代码很难说。

标签: c multithreading pthreads


【解决方案1】:

你可以使用pthread条件变量机制。不要对客户线程使用睡眠,只需使用pthread_cond_wait() 并由您的职员线程唤醒。

【讨论】:

    猜你喜欢
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 2015-05-28
    • 2013-06-04
    • 2018-10-13
    • 2022-11-03
    • 1970-01-01
    • 2012-03-18
    相关资源
    最近更新 更多