miracl / MIRACL

MIRACL Cryptographic SDK: Multiprecision Integer and Rational Arithmetic Cryptographic Library is a C software library that is widely regarded by developers as the gold standard open source SDK for elliptic curve cryptography (ECC).
https://miracl.com
654 stars 242 forks source link

Compile MIRACL as thread safe #30

Open liorko87 opened 8 years ago

liorko87 commented 8 years ago

Hi,

I'm using BN pairing (bls_pair). When I'm trying to run the program with two threads, I'm getting errors at runtime. This error aren't exist when I'm running the program at singe threading configuration.

I added to mirdef.h #define MR_UNIX_MT.

mcarrickscott commented 8 years ago

Hello Liorbiu,

Not really enough information to go on.

See the program threadux.cpp and look at the comments at the start. See can you get that program to run OK.

Maybe then use this program as a starting point for your own project.

Mike

On Tue, Sep 27, 2016 at 7:30 AM, liorbiu notifications@github.com wrote:

Hi,

I'm using BN pairing (bls_pair). When I'm trying to run the program with two threads, I'm getting errors at runtime. This error aren't exist when I'm running the program at singe threading configuration.

I added to mirdef.h #define MR_UNIX_MT.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/30, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jv0LxFv-d_z_LiZvNjlyWGxKLLxeks5quLgEgaJpZM4KHTPI .

liorko87 commented 8 years ago

Hello Mike,

Thanks for your quick reply. When I'm running threadux.cpp with this command : g++ -I. -D_REENTRANT -O2 threadux.cpp big.opp zzn.opp miracl.a -lpthread, the linker says the following error: undefined reference tomr_init_threading()`

mcarrickscott commented 8 years ago

Hmm. It would appear that you have not recompiled the MIRACL library with MR_UNIX_MT in mirdef.h

The function mr_init_threading is defined at the head of mrcore.c, using this code

ifdef MR_UNIX_MT

#include <pthread.h>
pthread_key_t mr_key;
miracl *get_mip()
{
    return (miracl *)pthread_getspecific(mr_key);
}

void mr_init_threading()
{
    pthread_key_create(&mr_key,(void(*)(void *))NULL);
}

void mr_end_threading()
{
    pthread_key_delete(mr_key);
}

endif

Clearly if MR_UNIX_MT were defined, then mr_init_threading() would exist, and the linker would find it.

Mike

On Wed, Sep 28, 2016 at 6:39 AM, liorbiu notifications@github.com wrote:

Hello Mike,

Thanks for your quick reply. When I'm running threadux.cpp with this command : g++ -I. -D_REENTRANT -O2 threadux.cpp big.opp zzn.opp miracl.a -lpthread, the linker says the following error: undefined reference tomr_init_threading()`

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/miracl/MIRACL/issues/30#issuecomment-250076603, or mute the thread https://github.com/notifications/unsubscribe-auth/ACm8jo1kqzUX8PwvJ2gwYICqn8RXaeUwks5quf2igaJpZM4KHTPI .