benoitc / offset

Other
379 stars 14 forks source link

Segmentation fault with many go routines #13

Open graffic opened 10 years ago

graffic commented 10 years ago

Running this program.

from offset import maintask, run, go, makechan

def gopher(left, right):
    value = right.recv()
    left.send(value + 1)

def starter(chan):
    chan.send(1)

@maintask
def main():
    leftmost = makechan()
    right = leftmost
    left = leftmost
    for _ in range(10000):
        right = makechan()
        go(gopher, left, right)
        left = right
    go(starter, right)
    print(leftmost.recv())

if __name__ == "__main__":
    run()

I get:

$ python gophers.offset.py
zsh: segmentation fault  python gophers.offset.py

The output I expected was 10001.

Tested with

I don't know if this is caused by the offset library, fibers library or any other combination so I decided to start from here. :)

benoitc commented 10 years ago

I reproduced it with python 3.4 as well. Reducing the number in the range make the problem disappear so I suspect a race condition.

I am about to replace the channels with an improved version, i will have a a look on that at the same time. Thanks for the test!

benoitc commented 10 years ago

it will be fixed with the new scheduler.