sptk



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

Re: r969 - trunk/src/utils



There is a problem with your changes. They require a separate call for mutex
lock, and this creates deadlock on Windows. By other words, this code isn't
portable.

2009/10/5 <iluxa@mail.total-knowledge.com>

> Author: iluxa
> Date: 2009-10-04 15:10:02 -0700 (Sun, 04 Oct 2009)
> New Revision: 969
>
> Modified:
>   trunk/src/utils/CWaiter.cpp
> Log:
> Unbreak watForSignal yet again
>
> Modified: trunk/src/utils/CWaiter.cpp
> ===================================================================
> --- trunk/src/utils/CWaiter.cpp 2009-10-04 21:04:42 UTC (rev 968)
> +++ trunk/src/utils/CWaiter.cpp 2009-10-04 22:10:02 UTC (rev 969)
> @@ -139,21 +139,21 @@
>  #endif
>  }
>
> +// NOTE. TO. HAPPY. SQUIRREL
> +// IT IS CALLER'S RESPONSIBILITY TO LOCK THE LOCK
> +// OTHERWISE RACE CONDITIONS ARE INTRODUCED
>  int CWaiter::waitForSignal(int timeout)
>  {
>  #ifndef _WIN32
> -    pthread_mutex_lock(&m_waiter);
>     if (timeout > 0) {
>         int secs = timeout / 1000;
>         int msecs = timeout % 1000;
>         struct timespec abstime = { time(NULL) + secs, msecs * 1000L };
>         int rc = pthread_cond_timedwait(&m_condition, &m_waiter, &abstime);
> -        pthread_mutex_unlock(&m_waiter);
>         if (rc == ETIMEDOUT)
>             return -1; // Timeout or error
>     } else {
>         pthread_cond_wait(&m_condition, &m_waiter);
> -        pthread_mutex_unlock(&m_waiter);
>     }
>  #else
>     DWORD rc = WaitForSingleObject(m_waiter,timeout);
>
>


-- 
Alexey Parshin,
http://www.sptk.net

List hosted by Total Knowledge

Authoright © Total Knowledge: 2005