Hi,
I have a code where I use threads, however in my code I use functions from a library (SSLeay) a lot of times inside the multiple threads, however the lib is not thread safe and as a result my code constantly segfault (it's unstable)...
Are there any trick to use non thread safes lib with threads in a way to it doesn't break/segfault my program?
I know the question appear very idiot, but I have no much options... without the threads the program is so slowww and i'm not skilled enought to write something like SSLeavy :) perlmodlib - Linux Command - Unix Command:: Some notes about ftp archives: Please use a long descriptive file name that You may need to make some minor changes (like escaping non-array @'s in http://linux.about.com/library/cmd/blcmdl1_perlmodlib.htmHOME |
Thank you,
Cheers
The simplest solution is to add one global mutex that is taken whenever a thread-unsafe library function is called, and released when the call returns.
That way you basically serialize on the library calls, probably slowing down things quite a bit, but if the library functions don't take that long (do not block, not doing any IO), it shouldn't be too bad.
Hi i3839,
Thank you for reply.
The simplest solution is to add one global mutex that is taken whenever a thread-unsafe library function is called, and released when the call returns.
That way you basically serialize on the library calls, probably slowing down things quite a bit, but if the library functions don't take that long (do not block, not doing any IO), it shouldn't be too bad.
Hummm... not the case.
My program is in perl, and I have no control about the SSL library it's all transparent for me, my code is simple like that:
if ($ssl) {
$request = new HTTP::Request GET => "https://$host/$uri";
} else {
$request = new HTTP::Request GET => "http://$host/$uri";
}
So I have threads exactly to do this calls, my threads are exactly to accelerate the number of paralel HTTP/HTTPS, If I lock/mutex each call in threads I will lost all my performance, at the end the speed will be like have no threads... :(
Thank you,
Cheers
Hi RobSeace,
Thank you for reply.
Also, I have a question: why are you using SSLeay?? That's utterly ancient and paperplanes. Tag archive: rails.:: Merb's run_later Coming to a Thread-safe Rails Near You Ben Nolan ( creator of Behaviour.js) showed some neat tricks using functional programming with http://www.paperplanes.de/archives/tags/railsHOME | hl 2040 driver - internet discussions | BoardReader:: It really is the depth that makes it a non-starter - Brother HL-2040 = 36.2 cm ! !! Quote: Originally Posted by stevo1 Why Hot threads on hl 2040 driver: http://boardreader.com/tp/hl+2040+driver.htmlHOME |
obsolete (and probably full of security holes)... It is what eventually (LONG ago)
turned into OpenSSL... You'd be much better off using a modern version of
OpenSSL, if you can...
http://www.openssl.org/support/faq.html#PROG1
Well, as I spoken to i3839 it's a perl code and all the complexity is in it, my code is extremely simple as you can see in my last post.
So who choose what to use (SSLeavy, OpenSSL, how to deal with private/public keys, negociate protocol, etc) is all a perl task.
I know it use SSLeavy cause when I run this code in Windows (activePerl) it say that need SSLeavy32.dll, etc.
Any miracle solution for me? Re-write the full code is not what I expect to read...hehe :)
Thank you a lot.
Cheers
Any miracle solution for me? Re-write the full code is not what I expect to read...hehe :)
Perhaps instead of running a single process with multiple threads in it, you could run multiple processes, each with a single thread? That way the non-thread-safe code in each process would still work.
-Jeremy
Hi Jeremy,
Thank you, yes, it's a simple and good idea, not sure if it will work, but i will try. :)
Thank you
Also, I have a question: why are you using SSLeay?? That's utterly ancient and
obsolete (and probably full of security holes)... It is what eventually (LONG ago)
turned into OpenSSL... You'd be much better off using a modern version of
OpenSSL, if you can...
http://www.openssl.org/support/faq.html#PROG1
1. Is OpenSSL thread-safe?
Yes (with limitations: an SSL connection may not concurrently be used by multiple threads). On Windows and many Unix systems, OpenSSL automatically uses the multi-threaded versions of the standard libraries. If your platform is not one of these, consult the INSTALL file.
Multi-threaded applications must provide two callback functions to OpenSSL by calling CRYPTO_set_locking_callback() and CRYPTO_set_id_callback(). (For OpenSSL 0.9.9 or later, the new function CRYPTO_set_idptr_callback() may be used in place of CRYPTO_set_id_callback().) This is described in the threads(3) manpage.
Traditional University or MLM University? You Choose
15 Questions to Ask Your Software Vendor
|