On Thu, Nov 29, 2012 at 9:57 AM, Staneva, Yana <ysten...@micros.com> wrote: > Help please. > > I have a Win32 application (service) that loads several dlls that make > OpenSSL calls. Also there is a separate dll that takes care of the OpenSSL > initialization (thread setup, SSL_library_init(), SSL_CTX_new() ). > > I’ve followed the samples online on how to do the thread setup, so I have > the following: > > #define MUTEX_TYPE HANDLE > > #define MUTEX_SETUP(x) (x) = CreateMutex( NULL, FALSE, NULL ) > > #define MUTEX_CLEANUP(x) CloseHandle(x) > > #define MUTEX_LOCK(x) WaitForSingleObject( (x), INFINITE ) > > #define MUTEX_UNLOCK(x) ReleaseMutex(x) > > #define THREAD_ID GetCurrentThreadId() Don't use these macros. On Windows, you must check return values (that's non-negotiable). WaitForSingleObject is especially egregious because it could lead to corruption. For example, if you accidentally close the Mutex, WaitForSingleObject will return ERROR_INVALID_HANDLE rather than the expected WAIT_OBJECT_0.
Boost is another offender. It ignores return values and suffer races in its threading gear. Be very careful if you are using that library on Windows. I can't explain all the defective code circulating. Folks must all be copy/paste'ing the same junky code. Jeff ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org