Re: Struct completion vs. semaphore

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

 



>>>>> "Jan" == Jan Hudec <bulb@ucw.cz> writes:

Jan> On Fri, Jun 21, 2002 at 05:11:26PM +0300, Momchil Velikov wrote:
>> >>>>> "Alan" == Alan Stern <stern@rowland.org> writes:
Alan> But you didn't answer my first question.  What are the essential
Alan> differences between a struct completion and a semaphore?
>> 
>> Hell if I can find any difference. Except that semaphores (in Linux
>> (the kernel)) have machine dependent implementations and are likely to
>> be much faster.

Jan> There is no "down" for completion. For semaphore, if you "up", exactly
Jan> one "down" succeeds. For completion, it you "compelte", all "wait"s
Jan> succeed from now on. You have to reinitialize it. And initializing is
Jan> not atomic. So completion is really just an encapsulation of waitqueue
Jan> whith conditional variable to simplify wait_on_event.

Not true. See the handling of the ``done'' field.  It is uncremented
in ``complete'' and decremented in ``wait_for_completion''. Just like
the semaphore count.

Jan> The semaphores are much more complicated and much more widely used, thus
Jan> tjey are partly in assembly.

*shrug*

Jan> Anyway, you CAN'T use completion for mutual exclusion and semaphores are

Of course, you CAN :) Just initialize it to 1 and than
``wait_for_completion'' is equivalent to lock and ``complete'' is
equivalent to unlock.

Regards,
-velco
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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