mirror of
https://github.com/janet-lang/janet
synced 2026-10-12 18:51:42 +00:00
Apply fix for threaded channels "eating" values.
Reported by @pepe with help from Claude.
This commit is contained in:
+3
-3
@@ -550,9 +550,9 @@ JANET_CORE_FN(janet_core_gensym,
|
||||
|
||||
JANET_CORE_FN(janet_core_gccollect,
|
||||
"(gccollect)",
|
||||
"Run garbage collection. You should probably not call this manually.") {
|
||||
"Run the garbage collector to free unreachable values.") {
|
||||
(void) argv;
|
||||
(void) argc;
|
||||
janet_fixarity(argc, 0);
|
||||
janet_collect();
|
||||
return janet_wrap_nil();
|
||||
}
|
||||
@@ -561,7 +561,7 @@ JANET_CORE_FN(janet_core_gcsetinterval,
|
||||
"(gcsetinterval interval)",
|
||||
"Set an integer number of bytes to allocate before running garbage collection. "
|
||||
"Low values for interval will be slower but use less memory. "
|
||||
"High values will be faster but use more memory.") {
|
||||
"High values will be faster but use more memory. Set to 0 to disable automatic collection.") {
|
||||
janet_fixarity(argc, 1);
|
||||
size_t s = janet_getsize(argv, 0);
|
||||
/* limit interval to 48 bits */
|
||||
|
||||
+4
-1
@@ -977,7 +977,10 @@ static void janet_thread_chan_cb(JanetEVGenericMessage msg) {
|
||||
break;
|
||||
}
|
||||
if (!sent) {
|
||||
janet_chan_unpack(channel, &x, 1);
|
||||
if (channel->closed || janet_q_push_head(&channel->items, &x, sizeof(Janet))) {
|
||||
/* channel is closed or full. Otherwise, keep it. */
|
||||
janet_chan_unpack(channel, &x, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
JanetChannelPending writer;
|
||||
|
||||
@@ -101,4 +101,17 @@
|
||||
(assert (deep= @"hello\nworld2\n" (slurp "tmp/out.txt")) "file threading 1")
|
||||
(assert (deep= @"world1\nabc\n" (slurp "tmp/out2.txt")) "file threading 2")
|
||||
|
||||
# A value given to a threaded channel whose only waiting reader has since been
|
||||
# resumed by another select clause must be kept for the next reader.
|
||||
(def stale-tchan (ev/thread-chan 10))
|
||||
(def stale-pchan (ev/chan 10))
|
||||
(ev/spawn (ev/select stale-tchan stale-pchan))
|
||||
(ev/sleep 0)
|
||||
(ev/give stale-pchan 1)
|
||||
(ev/sleep 0)
|
||||
(ev/give stale-tchan 42)
|
||||
(ev/sleep 0.01)
|
||||
(assert (= 42 (try (ev/with-deadline 1 (ev/take stale-tchan)) ([_] nil)))
|
||||
"value given to a threaded channel with a stale reader is kept")
|
||||
|
||||
(end-suite)
|
||||
|
||||
Reference in New Issue
Block a user