[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(no subject)
From michi1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Thu Apr 2 20:09:39 2009
Date: Thu, 2 Apr 2009 20:09:39 +0200
From: Michael Blizek <michi1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
To: Devesh Sharma <devesh28@xxxxxxxxx>
Cc: kernelnewbies@xxxxxxxxxxxx
Subject: Re: Usage of Semaphore with a workqueue
Message-ID: <20090402180939.GB1724@grml>
References: <309a667c0904010812p23ddde3fjda53a5d3e0250075@xxxxxxxxxxxxxx> <20090401164147.GB1738@grml> <309a667c0904020053j5ff6234cg4d57315568232925@xxxxxxxxxxxxxx>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <309a667c0904020053j5ff6234cg4d57315568232925@xxxxxxxxxxxxxx>
User-Agent: Mutt/1.5.18 (2008-05-17)
Status: RO
Content-Length: 2082
Lines: 53
Hi!
On 13:23 Thu 02 Apr , Devesh Sharma wrote:
> Hello Michael thanks for replying, My comments are inline below
>
> On Wed, Apr 1, 2009 at 10:11 PM, Michael Blizek
> <michi1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> > Hi!
> >
> > On 20:42 Wed 01 Apr , Devesh Sharma wrote:
> >> Hello list,
> >>
> >> Consider a case where I have a workqueue, a work is submitted to a it
> >> from some interrupt handler
> >> Lets say, some where in a code, it tries to get some semaphore to
> >> enter into a critical section,
> >> and fails to get it, sholud I still return from the work function by
> >> returning ERESTARTSYS?
> >
> > No, this is not a good idea. The work function which is called is expected to
> > return void. If you return ERESTARTSYS anyway, your function will not be
> > called again.
> So should I assume semaphores can not be used with workqueues?
No, this is not what I meant. You can use semaphores in workqueues. My point
was that if you need them for locking, you can use mutexes instead. Mutexes
are prefered over semaphores, for the reasons described in mutex-design.txt.
If all you do is locking and mutexes would be enough, using either mutexes or
semaphores will be fine (even tought some people will not like it, if you use
semaphores).
I just thought you might have a particular reason for using semaphores, like
avoiding to use wait_queue or something like this.
> if used
> and down_trylock() is used
> then some kind of wait mechanism has to be used?
If you want to wait, do not use down_trylock.
> Also what is the case
> with down_interruptible() is used?
The difference between down_trylock and down_interruptable is:
down_trylock: Try to lock the semaphore and if it is alreade locked, return
immediately with a return value which says the operation failed
down_interruptable: Try to lock the semaphore. If it is already locked, wait.
If a signal is received, return immediately without locking the semaphore.
-Michi
--
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ