cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-library Mailing List Archives

Re: HTTPS and Multi-threading

From: Andy Hobbs <andy_at_trogs.org.uk>
Date: Thu, 01 Jul 2004 09:07:23 +0100

Hi,

In newer versions of linux (kernel 2.4 and above) the getpid function
returns the parent pid not a unique thread ID per thread, you have to
use pthread_self() instead

Andy

On Wed, 2004-06-30 at 19:24, Olano, Ever wrote:
> Hello, Dirk. Sorry to bring this up again. In the OpenSSL
> documentation, it says of id_function():
>
> id_function(void) is a function that returns a thread ID. It is not
> needed on Windows nor on platforms where getpid() returns a different ID
> for each thread (most notably Linux).
>
> How come in your code below you had to set an id callback when you were
> targeting Linux (for which, according to the doc, it's not needed)?
> Didn't it work without one? Or you thought it wouldn't hurt? Does it
> work fine for you?
>
> Thanks,
> Ever
>
> ------------------------------------------------------------------------
> ----
> Message: 3
> Date: Fri, 11 Jun 2004 14:22:38 +0200
> From: Dirk Manske <dm_at_sysformance.com>
> Subject: Re: HTTPS and Multi-threading
> To: libcurl development <curl-library_at_cool.haxx.se>
> Message-ID: <200406111422.39016.dm_at_sysformance.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> On Wednesday 09 June 2004 03:14, Olano, Ever wrote:
> > 2. > What's that [mttest.c]?
> > It's the sample code in OpenSSL that shows how to implement and set
> > the callback functions needed for multithreading to work. I wanted to
> know if
> > anyone has tried it as I wanted to just copy it. Do you or anyone, by
> any
> > chance, have their own code for the locking and id callback functions?
>
>
> After a short look at mttest.c I wrote following code (for linux):
>
>
> static pthread_mutex_t *ssl_mutexes = NULL;
> static int ssl_mutexes_cnt = 0;
>
> void sslLocking(int mode, int n, const char *file, int line) {
> if( n < ssl_mutexes_cnt ) {
> if( mode&CRYPTO_LOCK ) {
> pthread_mutex_lock( &(ssl_mutexes[n]) );
> } else if( mode&CRYPTO_UNLOCK ) {
> pthread_mutex_unlock( &(ssl_mutexes[n]) );
> }
> return;
> }
> // error...
> }
>
> unsigned long sslThreadId(void)
> {
> return (unsigned long)pthread_self();
> }
>
> ...
>
> // create ssl mutexes
> ssl_mutexes_cnt = CRYPTO_num_locks();
> ssl_mutexes = (pthread_mutex_t*) malloc( ssl_mutexes_cnt *
> sizeof(pthread_mutex_t) );
> for( int i=0; i<ssl_mutexes_cnt; i++ ) {
> if( pthread_mutex_init( &(ssl_mutexes[i]), NULL ) != 0 ) {
> // error...
> abort();
> }
> }
> CRYPTO_set_locking_callback( sslLocking );
> CRYPTO_set_id_callback( sslThreadId );
>
> ....
>
> // free ssl mutexes
> if( ssl_mutexes ) {
> for( int i=0; i<ssl_mutexes_cnt; i++ ) {
> pthread_mutex_destroy( &(ssl_mutexes[i]) );
> }
> free( ssl_mutexes );
> }
>
>

-- 
andy_at_trogs.org.uk
I'd like to meet the guy who invented beer and see what he's working on
now
Received on 2004-07-01

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET