Skip to content
Advertisement

LINUX LISH.H list_for_each infinite loop

I’m trying to implement a list of task_struct and use it as a FIFO. In addition I need a function to go through the list and search for a particular task.

My problem is that the list_for_each macro gets stuck in an infinite loop.

Here below there is a snippet from my code:

JavaScript

Thanks in advance for any tips!

Advertisement

Answer

list_for_each() itself is fine.

JavaScript

The problem is: struct list_head task_list = sem->task_list;

You are creating a structure like:

JavaScript

list_for_each() should stop when "pos" == head #a, but you are not using head #a "sem->task_list" for iteration, but head #b "task_list", so the stop condition is "pos" == "task_list" is not reached.

Should fix like:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement