推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
bestehen
V2EX  ›  Python

为啥有的多线程的时候不加锁呢?

  •  
  •   bestehen · Aug 23, 2018 · 3113 views
    This topic created in 2955 days ago, the information mentioned may be changed or developed.

    https://blog.csdn.net/chivalrousli/article/details/77602863 这是一个多线程处理文件的 项目 就没有加锁实现的多线程,请问这是为啥呢?

    4 replies  •  2018-08-27 16:51:04 +08:00
    smilekung
        1
    smilekung  
       Aug 23, 2018
    因为没有资源竞争吧 每个线程各自处理不同目录的文件
    615915524
        2
    615915524  
       Aug 23, 2018
    cpu 密集型操作和 IO 密集型操作。

    后者没有锁
    Qzier
        3
    Qzier  
       Aug 25, 2018 via iPhone
    因为各个线程没有什么关联
    U87
        4
    U87  
       Aug 27, 2018
    @615915524 这话好像不对吧,仅就 py 而言,多线程也只是针对 io 密集型的,cpu 密集型没有真正意义上的多线程(因为 python 全局锁 GIL 的存在),所以多线程加不加锁是要看多线程之间有没有可能抢资源导致数据异常等问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2362 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 10:31 · PVG 18:31 · LAX 03:31 · JFK 06:31
    ♥ Do have faith in what you're doing.