c - linux 内核中 pthread_mutex_lock 和 pthread_cond_wait 的等价物

标签 c linux-kernel pthreads

linux 内核中的pthread_mutex_lockpthread_cond_wait 是什么等价物。以及如何使用它们。您能否提供简单的(hello world)示例。

最佳答案

  • 对于互斥量(如 Als 所说):

mutex_lock()mutex_unlock()我们应该在使用 mutex_init() 之前初始化互斥锁(来自 #include <linux/mutex.h>)

  • 相当于pthread_cond_wait

wait_event_interruptible()wake_up_interruptible()我们应该用 init_waitqueue_head() 初始化 wait_queue_head (来自 #include <linux/wait.h>)

关于c - linux 内核中 pthread_mutex_lock 和 pthread_cond_wait 的等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10104799/

相关文章:

c - 进程间共享内存和 pthread_barrier : how to be safe?

保存宏定义的C字符串

linux - 如何将 Linux 内核缓冲区映射到用户空间?

linux - 内存管理单元(MMU)如何通知操作系统页表更新了?

linux - 具有 undefined reference 错误的 udevadm 代码

windows - 是否可以在 Windows 中对互斥锁进行静态初始化?

c - pthread_join() 混合线程输出

c - 在 c 中杀死 child 后,尝试将变量从 child 添加到父亲时,fork 给出了奇怪的输出

c - 'FILE' 在 Contiki 中是未知类型

函数类型冲突?