Thread overview
[Issue 11695] std.net.curl https not thread-safe
Jul 20, 2015
brocolis
Dec 17
berni44
Dec 17
brocolis
Dec 17
berni44
Dec 17
brocolis
Dec 21
brocolis
June 10, 2015
https://issues.dlang.org/show_bug.cgi?id=11695

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |D2

--
July 20, 2015
https://issues.dlang.org/show_bug.cgi?id=11695

brocolis <brocolis@eml.cc> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |brocolis@eml.cc

--- Comment #1 from brocolis <brocolis@eml.cc> ---
Just in case someone else get hit by this bug, here's a working example for linux.

--
import std.net.curl;
import std.parallelism;
import std.range;
import std.stdio;

void main()
{
    init_locks();

    foreach(i; parallel(iota(0, 10, 1)))
    {
        writefln("Testing %d ...", i);
        get("https://...");
    }

    kill_locks();
}

import core.sync.mutex;
import core.stdc.config;
import core.sys.posix.pthread;
alias extern(C) c_ulong function() CRYPTO_set_id_callback_t;
alias extern(C) void function(int, int, const(char)*, int)
CRYPTO_set_locking_callback_t;
extern(C) int CRYPTO_num_locks();
extern(C) void CRYPTO_set_id_callback(CRYPTO_set_id_callback_t);
extern(C) void CRYPTO_set_locking_callback(CRYPTO_set_locking_callback_t);
enum CRYPTO_LOCK = 1;

__gshared Mutex[] mutex;

void init_locks()
{
    mutex.length = CRYPTO_num_locks();

    for (int i = 0; i < mutex.length; i++)
    {
        mutex[i] = new Mutex;
    }

    CRYPTO_set_id_callback(&thread_id);
    CRYPTO_set_locking_callback(&lock_callback);
}

void kill_locks()
{
    CRYPTO_set_id_callback(null);
    CRYPTO_set_locking_callback(null);

    foreach(m; mutex)
        destroy(m);

    mutex.length = 0;
}

extern(C) void lock_callback(int mode, int n, const(char)* file, int line)
{
    if (mode & CRYPTO_LOCK)
    {
        mutex[n].lock();
    }
    else
    {
        mutex[n].unlock();
    }
}

extern(C) c_ulong thread_id()
{
    return pthread_self();
}
--

--
December 17
https://issues.dlang.org/show_bug.cgi?id=11695

berni44 <bugzilla@d-ecke.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@d-ecke.de

--- Comment #2 from berni44 <bugzilla@d-ecke.de> ---
Getting linker errors, when trying the program von brocolis. Which compiler flags do I need to get access to CRYPTO_num_locks etc.?

--
December 17
https://issues.dlang.org/show_bug.cgi?id=11695

--- Comment #3 from brocolis <brocolis@eml.cc> ---
dmd bug.d -L-lssl

--
December 17
https://issues.dlang.org/show_bug.cgi?id=11695

--- Comment #4 from berni44 <bugzilla@d-ecke.de> ---
I'm still getting those linker errors. The same, when I use run.dlang.io

--
December 17
https://issues.dlang.org/show_bug.cgi?id=11695

brocolis <brocolis@eml.cc> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|brocolis@eml.cc             |

--
December 21
https://issues.dlang.org/show_bug.cgi?id=11695

brocolis <brocolis@eml.cc> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |brocolis@eml.cc

--- Comment #5 from brocolis <brocolis@eml.cc> ---
'dmd bug.d -L-lssl' just works for me (unmodified code from 2015-07)

--