本文介绍了如何进行内核线程通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让内核模块中的线程通信?我正在编写一个内核模块,而我的体系结构将使用三个需要通信的线程.到目前为止,我的研究使我相信唯一的方法是使用共享内存(声明全局变量)和锁定机制来同步线程之间的读取/写入.那里的材料很少.

How can I let threads in a kernel module communicate? I'm writing a kernel module and my architecture is going to use three threads that need to communicate. So far, my research has led me to believe the only way is using shared memory (declaring global variables) and locking mechanisms to synchronize reading/writing between the threads. There's rather scarce material on this out there.

还有其他方法可以考虑吗?内核代码中最常见的标准是什么?

Is there any other way I might take into consideration? What's the most common, the standard in the kernel code?

推荐答案

您没有说要在哪个操作系统上进行编程.我假设使用Linux,这是最常见的unix系统.

You don't say what operating system you're programming on. I'll assume Linux, which is the most common unix system.

有几本关于Linux内核编程的好书. Linux设备驱动程序可以在线获得,也可以在纸上获得. 第5章涉及并发性;您可以直接跳至第5章,尽管最好先略过第1章和第3章.随后的章节也有相关章节(特别是在第6章中讨论了等待队列). ).

There are several good books on Linux kernel programming. Linux Device Drivers is available online as well as on paper. Chapter 5 deals with concurrency; you can jump in directly to chapter 5 though it would be best to skim through at least chapters 1 and 3 first. Subsequent chapters have relevant sections as well (in particular wait queues are discussed in chapter 6).

Linux内核并发模型基于共享变量.同步方法的范围很广:原子整数变量,互斥锁(用于非阻塞临界区的自旋锁,用于阻塞临界区的信号灯),读取器-写入器锁,条件变量,等待队列,……

The Linux kernel concurrency model is built on shared variables. There is a large range of synchronization methods: atomic integer variables, mutual exclusion locks (spinlocks for nonblocking critical sections, semaphores for blocking critical sections), reader-writer locks, condition variables, wait queues, …

这篇关于如何进行内核线程通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 14:15