Karim Belabas on Wed, 21 Nov 2018 15:47:57 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Should newblock() be protected by BLOCK_SIGINT?


* Jeroen Demeyer [2018-11-21 15:29]:
> I was looking at the newblock/killblock code today and I noticed that
> killblock (better known as gunclone) is protected by BLOCK_SIGINT but
> newblock is not. It's not clear to me whether this is really a bug, but it
> seems safer to protect newblock also with BLOCK_SIGINT.

I don't think so:

1) the newly allocated block is unsafe as long as it's not completely
   initialized but it's unreachable as long it's not added to the
   linked list of blocks [either by bl_next(curblock) = x or cur_block =
   x on exit].

2) at the time it is linked / becomes reachable, it is complete (and safe
   for inspection, deletion or whatever)

So what happens if we interrupt in the middle of newblock() is that we lose
the memory allocated by pari_malloc, which is not a big deal.

gunclone is a more serious matter since we may partially unlink the
block x leaving the doubly list of blocks in an inconsistent state
(going forward and backward in the list would not run through the same
blocks). In this case, we block SIGINT to ensure the whole block deletion
becomes atomic.

Cheers,

    K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 21 23
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`