zoukankan      html  css  js  c++  java
  • advacing lnux program 4.4.7Deadlocks with Two or More Threads[copy]

    Deadlocks can occur when two (or more) threads are each blocked, waiting for a con-dition to occur that only the other one can cause. For instance, if thread A is blocked
    on a condition variable waiting for thread B to signal it, and thread B is blocked on a
    condition variable waiting for thread A to signal it, a deadlock has occurred because
    neither thread will ever signal the other.You should take care to avoid the possibility
    of such situations because they are quite difficult to detect.
    One common error that can cause a deadlock involves a problem in which more
    than one thread is trying to lock the same set of objects. For example, consider a pro-gram in which two different threads, running two different thread functions, need to
    lock the same two mutexes. Suppose that thread A locks mutex 1 and then mutex 2,
    and thread B happens to lock mutex 2 before mutex 1. In a sufficiently unfortunate
    scheduling scenario, Linux may schedule thread A long enough to lock mutex 1, and
    then schedule thread B, which promptly locks mutex 2. Now neither thread can
    progress because each is blocked on a mutex that the other thread holds locked.
    This is an example of a more general deadlock problem, which can involve not
    only synchronization objects such as mutexes, but also other resources, such as locks
    on files or devices.The problem occurs when multiple threads try to lock the same set
    of resources in different orders.The solution is to make sure that all threads that lock
    more than one resource lock them in the same order.

  • 相关阅读:
    【原创】使用开源libimobiledevice盗取iphone信息
    【原创】Arduino制作Badusb实践
    【原创】Aduino小车玩法全记录
    【原创】Arduino入门基础知识总结
    【原创】Arduino、arm、树莓派与单片机
    【原创】PM3破解IC卡记录
    【转】反编译D-Link路由器固件程序并发现后门
    DDOS分布式拒绝服务
    XSS 初识
    针对企业级别渗透测试流程
  • 原文地址:https://www.cnblogs.com/michile/p/2893434.html
Copyright © 2011-2022 走看看