Paul Durrant wrote:
On 29/05/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Paul Durrant wrote:
> On 28/05/07, Garrett D'Amore <[EMAIL PROTECTED]> wrote:
>> You should not attempt to acquire a lock which will be held by other
>> functions calling cv_wait, or its brethren. (There are ways to do that
>> safely, but it requires a fair bit of effort to make sure you do it
>> safely.)
>>
>
> I was not aware of this restriction, nor can I find it documented.
> This suggests that one cannot call cv_signal() from within an
> interrupt handler. Is this true?
>
>  Paul
>
Check the man page for cv_wait(9f) under CONTEXT.

Yes, I am aware of the restriction for cv_wait(). That makes sense.

 As for using cv_signal
in an interrupt handler, no problem.  Initially, at least, this was the
most common place for
cv_signal to be called.


But to call cv_signal() one must be holding the mutex that was
released by the call to cv_wait() in the other thread; thereby doing
something that Garrett suggests is unsafe.

 Paul

I assume you mean the bit quoted from Garrett at the top of this email. I think he was specifically talking about timeout functions, and about other mutexes (not the one used within the cv_wait call). You want to avoid this scenario:

Thread A Thread B (Interrupt context (or not)) mutex_enter(&l1); mutex_enter(&l1); /* problem is you don't get past here assuming */ /* Thread A got mutex l1 */ mutex_enter(&l2); mutex_enter(&l2);

while (condition ! met) /* condition has been met */
    cv_wait(&cv, &l2);    /* should release l1 first*/    cv_signal(&cv);

_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to