0

I have coded a program that works fine on windows, then I had to use it on linux so I coded the needed things for it to work on linux. What I mainly changed was the thread creation function ;

void thread_create(void *(*threadfunc)(void *), void *u)//linux
{
#ifdef linux
    pthread_t id;
    pthread_create(&id, NULL, threadfunc, u);
#endif
}

void thread_create(void (*threadfunc)(void *), void *u)//windows
{
#ifndef linux
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadfunc, u, 0, NULL);
#endif
}

The program has a lot of threads. I used gdb to see where it crashes, and the crash always occures at the curl_easy_perform function. Note that I am using this function a lot of times before where I know it will crash, the program never crashes before that point. When I am using them before that point, I'm not sending any data with POST/GET methods, I'm only getting informations from pages without sending any data.

So gdb always tells me :

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffdf65c700 (LWP 26488)]
0x00007ffff6fb0360 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff6fb0360 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00000000004a1e70 in readmoredata ()
#2  0x00000000004b33d7 in Curl_fillreadbuffer ()
#3  0x00000000004b40fc in Curl_readwrite ()
#4  0x000000000049b3bc in multi_runsingle ()
#5  0x000000000049c275 in curl_multi_perform ()
#6  0x00000000004972c3 in curl_easy_perform ()

I would like to give you something you can make tests on, but I really can't. The program has thousands of lines.

Neox
  • 279
  • 3
  • 13
  • There are a couple of very similar questions eg http://stackoverflow.com/questions/34998440/curl-crashes-in-threaded-calls and http://stackoverflow.com/questions/24589362/segfault-with-multithreaded-curl-request . Please check whether your issues is related or identical to these. – fvu Jul 03 '16 at 13:53
  • I saw these, but they are related with SSL etc, I don't use SSL :/ – Neox Jul 03 '16 at 13:54
  • As a side note, with C++11 you have unified thread support through `std::thread` and similars. If you have access to C++11 (and you should) then you can avoid messy `#ifdef` for different operating systems. – Jack Jul 03 '16 at 13:54
  • @Jack thank you, I didn't know this. I'll switch to this I guess, but later. – Neox Jul 03 '16 at 13:55
  • You have an existing bug in your code, somewhere, that results in undefined behavior. In the past I found existing bugs in my code after I compiled it on a different platform, with a different compiler. Good luck with your bug hunt. – Sam Varshavchik Jul 03 '16 at 13:57
  • @SamVarshavchik Thank you. I'll try to dig around and find that bug. But it's still weird, it always crashes for the same reason, and it doesn't crash before some point... the curl_easy_perform function is used like over 1k times before this. But I guess the bug occures after this. Oh well, thanks for your comment. – Neox Jul 03 '16 at 14:01
  • 1
    More context is needed to help narrow down your problem, but as a stab in the wild, is it possible you did not call curl_global_init() before launching your threads? If you don't, it will lazy-init during the first curl_easy_init() which is not thread safe and may be corrupting internal data which eventually causes your curl_easy_perform() to fail. – Nicholas Smith Jul 06 '16 at 23:57

0 Answers0