Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coroutines stuck whole program #22138

Open
imuxin opened this issue Aug 31, 2024 · 0 comments
Open

coroutines stuck whole program #22138

imuxin opened this issue Aug 31, 2024 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@imuxin
Copy link
Contributor

imuxin commented Aug 31, 2024

Describe the bug

When I use coroutine and channel to calculate a number of primes. It stuck!!

Reproduction Steps

execute: LD_LIBRARY_PATH=/path/to/thirdparty/photon/ v -use-coroutines run prime.v

prime.v (modified from 1.v):

module main

import os
import strconv
import coroutines as _

fn main() {
	mut n := 10
	if os.args.len > 1 {
		n = strconv.atoi(os.args[1]) or { n }
	}

	mut ch := chan int{cap: 1}
	go generate(ch)
	for _ in 0 .. n {
		prime := <-ch
		println(prime)
		ch_next := chan int{cap: 1}
		go filter(ch, ch_next, prime)
		ch = ch_next
	}
}

fn generate(ch chan int) {
	mut i := 2
	for {
		ch <- i++
	}
}

fn filter(chin chan int, chout chan int, prime int) {
	for {
		i := <-chin
		if i % prime != 0 {
			chout <- i
		}
	}
}

Expected Behavior

output:

2
3
5
7
11
13
17
19
23
29

Current Behavior

stuck

2
3
5
7
11
13

sometimes:

0x770355bb27fa: at ???: RUNTIME ERROR: division by zero
0x770355bb0056: by ???
0x770355baedb3: by ???
0x770355bae900: by ???
/tmp/v_1000/prime.01J6MGHPXB892MJFSAW0JTM9SC.tmp.c:33500: by main__main
/tmp/v_1000/prime.01J6MGHPXB892MJFSAW0JTM9SC.tmp.c:33711: by main

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7 8ebc288

Environment details (OS name and version, etc.)

uname -a

Linux ubuntu-mac 6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

photonwrapper.so from latest commit:

md5sum 4042c84a3ed49b47009b42487602c68b

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@imuxin imuxin added the Bug This tag is applied to issues which reports bugs. label Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant