c++ - Using OpenSSL in a multi-threaded application -
i have been writing soap client application in c++ on ubuntu using openssl https transport , pthreads threading. have number of threads - 1 central data acquisition thread periodically gets worker threads make soap requests via shared mutex protected queues.
reading documentation openssl found is openssl thread-safe? in openssl faq describes mechanisms required ensure thread safety when using openssl. implemented , works fine.
the reason question conceptual difficulty really. thinking implementing same functionality application has already, instead of using threads, create 2 seperate applications : 1 worker thread (of multiple copies running) , main data acquisition thread. use tcp sockets communicate between 2 rather mutex protected queues. may bad idea not important - confusing me would have implement same functions required ensure openssl thread safety in second approach or not?
my guess not have , treated independent (indeed surely must many applications use openssl) reason it?? what different between multiple applications using shared library code , multiple threads sharing same code?? have been writing multithreaded applications couple of years , concerns me cannot come answer question.
the difference when multiple threads share same library code, share same global data structures; when multiple processes share library code, don't.
for example, many of cryptographic algorithms in openssl faster if have large precalculated table available. table shared between multiple threads calling same openssl functions, locking must used ensure 1 thread attempts initialise table on first use.
as example, many openssl functions internally access random number generator, state of global data structure must have accessed synchronised across threads.
Comments
Post a Comment