Fwd: Free a list_head

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Umm I read linux kernel development and took a look at the example for using semaphores. But I still have the same problem.

AFAIK, down_interruptible if success, takes the lock, so no other process would be accessing the list at the same time... If it fails, the process will sleep and it will be woke up when the up() is performed... so I tried this:

retval = down_interruptible(&process_lock);

        if (!retval) {
                /*We need also to initialize the call_list list */
                list_for_each_entry_safe(p, my_node, &nodeList, list) {
                        list_del(&my_node->list);
                        kfree(my_node);
                }

                up(&process_lock);
        }
        return retval;


So if other process is accessing the list, I'll sleep. What happens when I resume execution of this context? just continue in the next line? or should I check something more?
Actually, I'm trying to implement a critical section in a simply way, this is, something like when I did with GTK:

gdk_threads_enter()
/*Critical region*/
gdk_threads_leave()

Maybe you could point me out to a good example on using semaphores inside the linux kernel
Regards. and thanks in advance
---------- Forwarded message ----------
From: Arjan van de Ven <arjan@xxxxxxxxxxxxx>
Date: Jul 13, 2006 9:44 PM
Subject: Re: Free a list_head
To: Fernando Apesteguía < fernando.apesteguia@xxxxxxxxx>
Cc: Greg KH <greg@xxxxxxxxx>, kernelnewbies < kernelnewbies@xxxxxxxxxxxx>


> down_interruptible(&process_lock);

note that you're not checking the return value of
down_interruptible() !!
down_interruptible does not always actually take the lock, and it tells
you that via the return value. If you don't check that..... you are in
deep trouble when that happens



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux