bug-commoncpp
[Top][All Lists]
Advanced

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

RE: can't release mutex


From: Conrad T. Pino
Subject: RE: can't release mutex
Date: Sat, 27 Jan 2007 10:43:07 -0800

You're on the right track.  Please pardon my rusty recollection syntax.
Revise:

        mutex.enterMutex();

to a form that accepts a timeout.  This example won't compile:

        const int timeout = 500;

        while (1) {
                if ( isPending( pendingInput ) ) {
                        int result = mutex.enterMutex( timeout );

                        if ( result == success ) {
                                ---> protected function call (a function that 
can't work 
                                in multithread env) <---       
                                mutex.leaveMutex();
                        } else {
                                // do something else with pending input
                        }
                }
        }

While the above will implement your timeout idea it does nothing about
the fundamental problem.  When the library "breaks" can be discoverd
and the blocked mutex/thread combination can be cancelled/restared
HOWEVER PROPRIETARY LIBRARY STATE IS INCONSISTENT & LIKELY DANGEROUS.

If the library is dynamically loaded under your control then unload it
and reload it to get it back into a consistent state.  If it's auto or
static linked then you may have an unsolveable problem.

If a reliable system is your goal then one of these MUST be true:

                proprietary library NEVER fails
        OR
                proprietary library can be forced back to a consistent
                state because it has a reload or reinitialize method

Good luck.

> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden Behalf Of Wakan
> Sent: Saturday, January 27, 2007 07:18
> To: address@hidden
> Subject: can't release mutex
> 
> Hi,
> I'm using commoncpp library in a project that includes a multithread 
> server that
> can accept many tcp connection and each connection generates a thread.
> In this server I'm using a thirdy party proprietary library (compiled), 
> that (as the producer says)
> can't work in multithread environment.
> As each connection thread needs to call functions of this thirdy party 
> library, I've used a mutex to protect the piece of
> code where this external library function is called.
> In this way I can use this library fine, because all calls are 
> serialized and the protected function is called by one thread each time.
> This is an example:
> ...
>     while(1) {
>         if(isPending(pendingInput)) {
>                 mutex.enterMutex();
>                 ---> protected function call (a function that can't work 
> in multithread env) <---       
>                 mutex.leaveMutex();
>        }
>     }
> ...
> in 99% of cases it works fine. But it accidentally happens that a thread 
> can't exit from the mutex
> maybe because the thirdy party function freezes itself.
> When this happens, the server can accept other connections, soit still 
> works, but each thread can't enter in the mutex proteced piece of code.
> I'm thinking about something, like a timeout, that exits the mutex after 
> a time, if the thread is not exiting...
> Can someone help me to resolve this problem? Are there other solutions?
> Thanks in advance,
> Regards
> Carlo





reply via email to

[Prev in Thread] Current Thread [Next in Thread]