[PATCH] Protect Kernel cache against async interrupts by timeout

5 views
Skip to first unread message

Qian Yun

unread,
Jul 18, 2026, 7:56:22 AM (4 days ago) Jul 18
to fricas-devel
I introduced a new macro "WITHOUT_INTERRUPTS" to prevent
a block of code entering interrupts by timeout.

During testing, I've added a debugging function to check
if the position of kernel cache elements are ascending.
Before the patch, it is easy to detect kernel cache
inconsistency after a few thousands integrals with timeout.
After the patch, one 20k and several 10k integrals tests
are passed without problems.

- Qian
protect-kernel-cache-against-timeout.patch

Waldek Hebisch

unread,
Jul 18, 2026, 8:37:39 AM (4 days ago) Jul 18
to fricas...@googlegroups.com
OK, please commit.

> diff --git a/src/algebra/kl.spad b/src/algebra/kl.spad
> index 81383ad0..d2a2187d 100644
> --- a/src/algebra/kl.spad
> +++ b/src/algebra/kl.spad
> @@ -58,11 +58,12 @@ SortedCache(S : CachableSet) : Exports == Implementation where
>
> expandCache(x) ==
> if cache_size = cache_use then
> - ocache := cache
> - cache_size := 2*cache_size + 10
> - cache := new(cache_size, x)$(PrimitiveArray S)
> + ncache_size := 2*cache_size + 10
> + ncache := new(ncache_size, x)$(PrimitiveArray S)
> for k in 0..(cache_use - 1) repeat
> - cache(k) := ocache(k)
> + ncache(k) := cache(k)
> + cache := ncache
> + cache_size := ncache_size
> void
>
> insertBefore(l, x) ==
> @@ -182,9 +183,10 @@ SortedCache(S : CachableSet) : Exports == Implementation where
>
> insertInCache(before, x, pos) ==
> y := cache(before)
> - if ((pos+1) = position y) then shiftCache(before, DIFF)
> + if ((pos+1) = position y) then
> + WITHOUT_INTERRUPTS(shiftCache(before, DIFF))$Lisp
> setPosition(x, pos + (((position y) - pos)::N quo 2))
> - insertBefore(before, x)
> + WITHOUT_INTERRUPTS(insertBefore(before, x))$Lisp
> x
>
> )abbrev domain MKCHSET MakeCachableSet
> diff --git a/src/lisp/primitives.lisp b/src/lisp/primitives.lisp
> index de3fa064..946b727d 100644
> --- a/src/lisp/primitives.lisp
> +++ b/src/lisp/primitives.lisp
> @@ -898,3 +898,8 @@
> `(let ((|$BreakMode| '|trapSpadErrors|))
> (declare (special |$BreakMode|))
> (CATCH '|trapSpadErrors| ,form)))
> +
> +(defmacro WITHOUT_INTERRUPTS (&rest form)
> + `(#+:sbcl sb-sys:without-interrupts
> + #-:sbcl progn
> + ,@form))


--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages