GZGQ.COM
welcome to my space
X
Search:  
 HOME   Some hot trick to use threads with non thread safe libs?
Some hot trick to use threads with non thread safe libs?
Published by: smith 2009-01-08
Welcome to:gzgq.com

  • 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.htm
    HOME

    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/rails
    HOME
    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.html
    HOME
    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

    You are looking at:gzgq.com's Some hot trick to use threads with non thread safe libs?, click gzgq.com to home
  • how to install compiz fusion on ubuntu
  • want distro h w pentium s 75mhz 8mb ram
  • bunch of problems related to grub
  • what you did to your super l key window key
  • k3b not burning
  • how get a list of build essential for ubuntu
  • my system tempratures in ubuntu are they normal
  • some problem with vector linux
  • linux elevator speech help
  • installation sequence of os
  • how to install boot loader to mbr in ubuntu
  • splash screen help
  • need open suse 10 2 dvd
  • netgear wg511v2 on debian issues
  •  
  • con kolivas ck kernel patch set to be discontinued
  • install linux help pl
  • add drive shortcuts on desktop in ubuntu
  • can t get display working in ubuntu help needed
  • finally new ati linux gpu drivers don t suck
  • how do i go about installing linux
  • linux on pendrive xgl compiz beryl
  • how to install softwares without internet
  • rar problem
  • need help on fedora core 6
  • boot screen and im
  • 10 minutes to run every windows app on your ubuntu desktop
  • how to rectify this
  •  Homepage | Add to favorites | Contact us | Exchange links | LOGIN | Site map | 
    Copyright© 2008 gzgq.com        Site made:CFZ