jpmelos
jpmelos

Reputation: 3562

How can I make kernel thread communication?

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?

Upvotes: 3

Views: 1579

Answers (1)

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

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).

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, …

Upvotes: 2

Related Questions