Feedback
Feedback

If you are having issues with the exercises, please create a ticket on DevZone: devzone.nordicsemi.com
Drag & Drop Files, Choose Files to Upload 您最多可以上传 2 个文件。
  • 简体中文
    Eng
    简体中文
  • 线程同步

    在多线程应用程序中,有多个线程并发运行。如果多个线程尝试同时访问同一个资源(变量、数据结构等),这通常被称为临界区,可能会导致意外或错误的行为。这就是需要线程同步的原因;它是一种确保在任何给定时间内只有一个线程执行临界区的机制。

    您可以利用信号量或互斥锁这两种机制来实现线程同步。它们具有一些不同的属性,但本质上都是由线程在临界区前后更改的变量,以确保在该线程完成之前,没有其他线程可以执行该段代码。主要区别在于,信号量在初始化时设置了最大值,而互斥锁具有所有权属性,即只有增加其值的线程才能对其进行递减,直到归零时将其释放。

    在接下来的章节中,我们将更详细地讨论信号量和互斥锁,包括属性列表和可视化演示。此外还有两个练习需要完成,旨在练习如何使用信号量和互斥锁作为线程同步机制。

    Switch language?

    Progress is tracked separately for each language. Switching will continue from your progress in that language or start fresh if you haven't begun.

    Your current progress is saved, and you can switch back anytime.

    Register an account
    Already have an account? Log in
    (All fields are required unless specified optional)

    • 8 or more characters
    • Upper and lower case letters
    • At least one number or special character

    Forgot your password?
    Enter the email associated with your account, and we will send you a link to reset your password.