pdf-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pdf-devel] libcurl initialization requirements


From: jemarch
Subject: Re: [pdf-devel] libcurl initialization requirements
Date: Wed, 17 Feb 2010 20:46:01 +0100
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/23.1.91 (i686-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

   I just noticed that libcurl requires a call to curl_global_init()
   while the program as a whole is single-threaded.  The libcurl docs
   make this quite clear.

   Are we willing to impose this kind of an initialization requirement on
   any and all applications that would link with us?  The requirement
   would be that if http filesystem is included (using libcurl) we would
   need to call curl_global_init while there is only one thread in the whole
   application.  This could mean that we have to be the first lib initialized
   to rule out any other libraries spawning a thread.

   Can we really proceed with libcurl?

From http://curl.haxx.se/mail/lib-2008-02/0120.html :

    > Because if it is true, it would make it impossible to use curl
    > in libraries that are dynamically loaded by other programs (like
    > plug-ins), because you can never be sure that no threads are
    > running.

    If you use libcurl in a plugin that is run in an invidiual thread
    and your plugin calls curl_global_init() and there might be more
    than one plugin like this running within the same program, then
    correct you cannot safely use this approach.

    But the problem is not really running it in multiple threads, the
    problem is when you run the inits simultaneously in multiple
    threads so for your plugin example you can make some mutex magic
    that prevents the race to happen.

So it seems that it would be safe to call curl_global_init in
pdf_init.  We just have to warn the user to not call curl_global_init
in any other part of the program if the http module is going to be
used.

It would be nice for libcurl to provide a way to atomically check if
curl_global_init has been called before.  Could you make sure it
isn't?  If it isn't, maybe you could ask the libcurl maintainers to
add that functionality.

-- 
Jose E. Marchesi  <address@hidden>
                  http://www.jemarch.net
GNU Project       http://www.gnu.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]