Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Is it safe to iterate task list without any lock? #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iwoeruhsdfwoi opened this issue Feb 9, 2022 · 1 comment
Closed

Is it safe to iterate task list without any lock? #11

iwoeruhsdfwoi opened this issue Feb 9, 2022 · 1 comment

Comments

@iwoeruhsdfwoi
Copy link

I'm not sure whether it's safe to traverse this list without any lock. I examined all usages and most of them are protected by rcu_read_lock() or read_lock(&tasklist_lock).

@kaiwan
Copy link
Collaborator

kaiwan commented Feb 11, 2022

Hi @iwoeruhsdfwoi , thanks for your comment.
You're right reg the need for protection.
Do understand though, that this is a book where the reader makes progress as (s)he covers each chapter.
The locking / synchronization details are left to the last two chapters...
In fact, this statement in the book in Ch 6 (pg 311 of the e-book) hints at this:

...
We print the name of the thread as well (by looking up the comm member of
the task structure). You might question why we don't use the get_task_comm() routine to obtain the task's name here; the short
reason: it causes a deadlock! We shall explore this (and how to avoid it) in detail in the later chapters on kernel synchronization. For now, again, we just do it the simple way.
...

This is again mentioned in Ch 12 pg 668, mentioning the fact that as tasklist_lock isn't exported, it isn't available to modules.
The RCU read lock can be used; I shall add it.
As you've written reg this, I'll update the code (and relevant info in a comment in these examples). Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants