Git Product home page Git Product logo

lthread's Introduction

lthread's People

Contributors

arangamani avatar halayli avatar hhoffstaette avatar markpeek avatar robxu9 avatar semistrict avatar waywardmonkeys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lthread's Issues

Mac issue

lthread.c:538:63: error: format specifies type 'long' but the argument has type '__darwin_suseconds_t' (aka 'int') [-Werror,-Wformat]

Windows support

Is windows support planned?

Thanks a lot for this awesome gem!

lthread_join is misleading

When calling lthread_join, you need check return result before freeing the lthread struct.
It is too easy to cause memory leak or corruption.

A better solution is to follow pthread_join behavior: No timeout parameter. The caller need to free 'lthread' struct.

Incorrect time calculation in scheduler on 32 bit systems

There is a bug in integer addition in _lthread_usec_now(): signed long time_t overflows. The return statement must look like this:

/* _lthread_usec_now(): */
    return (uint64_t) t1.tv_sec * 1000000 + t1.tv_usec;

Bug shows itself as follows - after some point in time lthread functions with timeouts start trashing the cpu, in my case it was lthread_read(). I've found this after I was unable to recover seconds from sched->birth on my 32bit box.

-DNDEBUG causes segfault

Disabling the asserts with -DNDEBUG in CFLAGS causes a segmentation fault in _lthread_poller_ev_register_trigger () on Linux x86_64.

Assertion failed: (lt_write != NULL || lt_read != NULL), function lthread_run, file lthread_sched.c, line 252.

To run an lthread scheduler in each pthread, launch a pthread and create lthreads using lthread_create() followed by lthread_run() in each pthread.

when create more then one pthread and lthread scheduler,and use "ab -c 100 -n 10000" to test program,then "Assertion failed: (lt_write != NULL || lt_read != NULL), function lthread_run, file lthread_sched.c, line 252." occure.

But only one pthread will run ok.

lthread_poll assertion error

I'm getting this assertion error: lthread/src/lthread_sched.c:252: lthread_run: Assertion `lt_write != ((void *)0) || lt_read != ((void *)0)' failed.

Trying this with some basic code:

pollfd p;
memset(&p, 0, sizeof(p));
p.fd = fd;
p.events = POLLIN;
lthread_poll(&p, 1, 1000000);

If I substitute these lines of code for:

lthread_wait_read(fd, 0);

Then it waits just fine.

select?

A way to poll on multiple fds at once would be nice.

lthread_sleep() bug?

May be exists bug when call function lthread_sleep(0), because current CPU context was lose.

lthread_create not initializing new_next and sleep_next correctly?

new_next and sleep_next are initialized as follows:
lt->new_next.le_next = NULL;
lt->new_next.le_next = NULL;
lt->sleep_next.le_prev = NULL;
lt->sleep_next.le_prev = NULL;

should it not be as follows?
lt->new_next.le_next = NULL;
lt->new_next.le_prev = NULL;
lt->sleep_next.le_next = NULL;
lt->sleep_next.le_prev = NULL;

compile as shared lib

If I attempt to link liblthread.a with other code to create a shared library (.so), then I get the following error:

/usr/bin/ld: /usr/local/lib/liblthread.a(lthread.c.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/liblthread.a: could not read symbols: Bad value

I tried recompiling lthread with -fPIC and this was enough to get the shared lib to successfully link with liblthread.a and produce a .so file. Unfortunately, the shared lib misbehaves at runtime. Specifically, I get this assertion:

lthread_sched.c:231: lthread_run: Assertion `lt_write != ((void *)0) || lt_read != ((void *)0)' failed.

It seems getting this to work as a shared lib requires a bit more thought than blindly adding -fPIC.

ability to poll on an fd without reading from it

This is needed to integrate other event-driven-capable libraries like libzmq or libcurl. They expect to be woken up whenever certain fds become readable/writable, but they expect to be the ones doing the actual reading/writing.

I was able to get this to work by making _lthread_sched_event() public, and for example calling _lthread_sched_event(lthread_current(), fd, LT_EV_READ, 0) to wait until an fd becomes readable.

Would be nice to see some kind of solution in the public API. Libtask has fdwait() for this purpose.

Some confusions about schedule

Hi, good afternoon.

I read the source code, and I find the lthread looks good.
BUT Is there still something needs to be done before being applied?

For example. In the webserver demo. Just one thread is working for polling, computing, and doing functions in lthreads.
If I want to make lthread high-performance, Moving those computing tasks and functions to other pthreads would be better?
Maybe I can send a msg to other pthreads to reduce the burdens of the main pthread(epoll thread)?

Core dump is thrown in lthread_compute_end()

When I tried to run example program (webserver.c), it crashes with core dump.
With gdb program halts at following:

Program received signal SIGSEGV, Segmentation fault.
0x001352ea in lthread_compute_end () at lthread_compute.c:126
126     asm("movl %0, 0(%%ebp)\n" ::"a"(lt->ebp));

Library and program compiled on Linux 3.0.0-16-generic #29-Ubuntu SMP i686 i686 i386 GNU/Linux

Should use monotonic clock instead of gettimeofday

The result of gettimeofday is the wall clock which can change backwards in some occassions (time drifted and ntp re-enabled). In that case timeouts may not expire for a while until the wall clock catches up.

It is better to use CLOCK_MONOTONIC with clock_gettime() to get a stable clock that never moves backwards.

Error building under MacOSX but have a solution

By removing "inline" from void _lthread_renice(struct lthread *lt) fixes compiling (see build error below) on MacOSX. I edited src/lthread_int.h and removed the inline keyword.

Performed a cmake .; make and it worked great.

Might be worth removing inline or adding preprocessor condition for MacOSX.

--Build Error--------------------
[ 11%] Building C object CMakeFiles/lthread.dir/src/lthread_socket.c.o
In file included from /Users/user/Projects/coroutines/lthread/lthread-master/src/lthread_socket.c:42:
/Users/user/Projects/coroutines/lthread/lthread-master/src/lthread_int.h:184:13: error: inline function '_lthread_renice' is not defined [-Werror,-Wundefined-inline]
inline void _lthread_renice(struct lthread *lt);
^
/Users/user/Projects/coroutines/lthread/lthread-master/src/lthread_socket.c:147:9: note: used here
_lthread_renice(lt);
^
1 error generated.

ucontext compat layer?

Hi would lthread be able to provide a ucontext compat layer? This is needed for libcs that don't provide ucontext

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.