When I == 1, you have five_back negative and effectively robots_count(train. Waiting-1) after 2 iterations.
Up vote 0 down vote favorite share g+ share fb share tw.
So I'm working on a linux Kernel module which requires an infinite waiting loop in a separate thread initiated by kthread. The following is the function run by kthread, and train. Queue_mutex is a mutex initialized before kthread (via mutex_init(&train.
Queue_mutex)) I cannot for the life of me figure out why it locks the kernel. My thinking is that between the mdelay and the schedule() every iteration, other processes should get CPU time. Int train_thread(void *param) { while (!train.
Is_deactivating) { mutex_lock_interruptible(&train. Queue_mutex); while (train. Num_waiting > 0) { int five_foward = (train.
Stop + 5) % 10; int five_back = (train. Stop - 5) % 10; int I = train. Stop; int max_count = 0; int max_count_index = 0; for (;i!
= five_foward; I = (i + 1) % 10) { int count = robots_count(train. Waitingi); if (count > max_count) { max_count_index = i; max_count = count; } } for (i = train. Stop ;i!
= five_back; I = (i - 1) % 10) { int count = robots_count(train. Waitingi); if (count > max_count) { max_count_index = i; max_count = count; } } // Should have max_count_index set to index of stop with the most bots printk("Most bots %d at stop %d\n", max_count, max_count_index); mutex_unlock(&train. Queue_mutex); schedule(); mutex_lock_interruptible(&train.
Queue_mutex); } mutex_unlock(&train. Queue_mutex); mdelay(10); } train. Is_active = 0; return 0; } c linux multithreading kernel link|improve this question edited Mar 15 '11 at 0:10ninjalj11.9k11431 asked Mar 14 '11 at 22:51Ben40718 100% accept rate.
– Gabe Mar 14 '11 at 22:53 I think that was meant to say "round" - edited. – Ben Mar 14 '11 at 22:56 1 Just to check, did you put in print statements to make sure one of your for loops isn't infinite looping? – Jeff Mar 15 '11 at 0:16.
For (i = train. Stop ;i! = five_back; I = (i - 1) % 10) { int count = robots_count(train.
Waitingi); When I == 1, you have five_back negative and effectively robots_count(train. Waiting-1); after 2 iterations.
Once you've fixed the logic problem pointed out by bestsss you still have the problem that mdelay() is a busy-wait, which does not release the CPU. You should consider schedule_timeout() or msleep. Take a look in Linux Device Drivers for more details.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.