|
From: | Wakan |
Subject: | Re: can't release mutex |
Date: | Sat, 27 Jan 2007 21:04:55 +0100 |
User-agent: | Mozilla Thunderbird 1.5.0.9 (Windows/20061207) |
Thanks very much for your kind reply! I think the problem is elsewhere... When the thread the calls the proprietary function never runs to the mutex.leaveMutex(), say because the function doesn't be able to exit for an internal break, all other threads will continue to loop in vain....because the mutex will never be released. What I need is something (maybe another thread) that checks if a thread is jammed (with a timer) and in this case tell it to exit, or kill it (because if a thread is jammed, can't go on...so can't check for timeouts or exit flags)... Sorry for my poor english....hope it is clear enought Thanks in advance for you help, Carlo Conrad T. Pino ha scritto: 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]On 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__________ NOD32 2011 (20070127) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com |
[Prev in Thread] | Current Thread | [Next in Thread] |