[Stackless] Problem building release27-maint in 64-bit linux.

Alexey Borzenkov snaury at gmail.com
Wed Aug 17 19:11:24 CEST 2011

On Wed, Aug 17, 2011 at 10:13 AM, Richard Tew <richard.m.tew at gmail.com> wrote:
> On Wed, Aug 17, 2011 at 12:36 AM, Alexey Borzenkov <snaury at gmail.com> wrote:
>> 2. crashes can happen if there's any C-stack switch during garbage
>> collection. The reason for this is that Python is creating gc lists on
>> the stack, and if during tp_clear there are C-stack switches (as in,
>> to kill an alive greenlet/tasklet), then those variables might get
>> clobbered. If during the switch there are deallocations, and list head
>> is updated, it would lead to random stack corruptions. Now these
>> conditions are extremely rare, but they can happen and can lead to
>> weird crashes. If anyone is interested you can read how I found this
>> issue here: https://bitbucket.org/ambroff/greenlet/issue/24/debian-64-errors-with-pydebug
> Not a problem in Stackless, see the following code:
> #ifdef STACKLESS
>    /* unlinking may occur in a different tasklet during collection
>     * so these must not be on the stack
>     */
>    static PyGC_Head unreachable; /* non-problematic unreachable trash */
>    static PyGC_Head finalizers;  /* objects with, & reachable from, __del__ */
> #else
>    PyGC_Head unreachable; /* non-problematic unreachable trash */
>    PyGC_Head finalizers;  /* objects with, & reachable from, __del__ */
> #endif

Hmm, but doesn't it make Stackless not thread-safe as a result? What
if some finalizers cause threads to switch and another thread starts
to collect garbage too? To have it thread-safe wouldn't you need to
make it thread-local, e.g. in a thread state?

More information about the Stackless mailing list