-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
occasional SIGSEGV when using threadpool and channels #5626
Comments
I suppose import threadpool
var ch: Channel[int]
ch.open
var pch = ch.addr
var working = false
proc handler(): int =
while true:
let (h, v) = pch[].tryRecv()
if not h:
discard cas(working.addr, true, false)
break
1
proc run(): proc() =
let r = spawn handler()
return proc() = await(r)
proc send(x: int) =
ch.send(x)
if cas(working.addr, false, true):
discard run()
for x in 0..1000000:
send(x) |
No longer crashes with #head.
|
On my Ubuntu 16.04
If compiled with -d:release it doesn't crash. But what should this program actually do?
It effectively stops after a random number of The test case from #8204 only tests if the program can be compiled. It doesn't run it. With a discard """
action: run
""" block at the top it would probably fail on the CI platforms. |
|
Please reopen this, it is broken on Linux. |
How come testament doesn't run this? Nim/tests/testament/categories.nim Lines 200 to 208 in c7cc934
Per the code, all threading test cases are executed with |
Good catch, mayb it did run it and yet it was green. |
Nope, it doesn't run - setting Nim/tests/testament/tester.nim Lines 298 to 302 in c7cc934
The default value of action ends up being I think this code should be changed to: if test.action != actionRunNoSpec:
expected = parseSpec(tname)
if test.action == actionRun and expected.action == actionCompile:
expected.action = actionRun
else:
specDefaults expected
expected.action = actionRunNoSpec Feedback appreciated. |
Sounds good. |
This happens with Nim 0.19.4 on Linux: All receiver block after receiving 2 or 202, 3 and 303 and later are never received. import os
import threadpool
import times
type EventChannel = Channel[int]
proc sender(c: ptr EventChannel, starting_from:int) {.thread.} =
for i in 0..5:
doAssert c[].trysend(i + starting_from) == true
echo "sent " & $(i + starting_from)
sleep 10
proc sender_broken(c: ptr EventChannel, starting_from: int) {.thread.} =
var chan = c[]
for i in 0..5:
doAssert chan.trysend(i + starting_from) == true
echo "sent " & $(i + starting_from)
sleep 10
proc receiver(pc: ptr EventChannel, n:int) {.thread.} =
var chan = pc[]
chan.open(0)
while true:
echo $n & " blocks"
let x = recv(chan)
echo($n & " received from chan: " & $x)
var chan: EventChannel
chan.open(0)
spawn sender(addr chan, 0)
spawn sender_broken(addr chan, 100)
spawn sender(addr chan, 200)
spawn receiver(addr chan, 1)
sleep 10
spawn receiver(addr chan, 2)
sleep 10
spawn receiver(addr chan, 3)
sleep 500
echo "Finished listening"
close(chan) Occasional SIGSEGV:
|
It's invalid to copy a channel like this |
@FedericoCeratto, I've tried your code example with Nim devel v1.3.5 and i couldn't reproduce the SIGSEGV. Can you confirm? |
The missed keyword was occasional SIGSEGV — I was writing the test case for this, everything was passing at first, and then I noticed it fails sometimes, in ~1/4 of the runs. |
Use Malebolgia instead and avoid channels with thread pools. |
crashes with error:
The text was updated successfully, but these errors were encountered: