aslze / asl

A compact C++ cross-platform library including JSON, XML, HTTP, Sockets, WebSockets, threads, processes, logs, file system, CSV, INI files, vectors and matrices, etc.
Other
69 stars 17 forks source link

asl::sleep causes a SEGFAULT in raspberry pi #2

Closed xjrsanchezx closed 6 years ago

xjrsanchezx commented 6 years ago

Using Linux raspberrypi 4.14.50+ gcc version 6.3.0 20170516

asl::sleep triggers SEGFAULT

aslze commented 6 years ago

I've never tried this on a Raspberry pi. That will take time.

It's strange. asl::sleep on non-Windows just calls sleep() or usleep(). May it be that it is calling itself and producing a stack overflow?

What if you change in time.h:73:

inline void sleep(int s)
{
    sleep((unsigned)s);
}

to

inline void sleep(int s)
{
    ::sleep((unsigned)s);
}

so it calls the global unix function. Or to usleep(1000000*s).

xjrsanchezx commented 6 years ago

Thanks! You are right. In fact it only crashes with the int version of the function. Another alternative to fix the problem is calling the version that uses double:

inline void sleep(int s)
{
    sleep((double)s);
}

:thumbsup::thumbsup:

aslze commented 6 years ago

I guess this is fixed. Please reopen if needed.