| Bill Allombert on Thu, 11 Dec 2025 13:30:37 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: PARI/GP 2.17.2 testsuite hangs nondeterministically (macOS) |
On Wed, Dec 10, 2025 at 12:03:43PM +0100, Bill Allombert wrote: > On Sun, Oct 26, 2025 at 02:21:37PM -0700, Matthias Koeppe wrote: > > Unsurprisingly, builds using the clang compilers provided by > > conda-forge are also affected. > > https://github.com/passagemath/passagemath/actions/runs/18811959899/job/53674549752#step:10:2578 > > The following stand-alone program that does not use libpari also hangs when run > repeatly. > > Try for example > for i in `seq 1 2000`; do echo $i; ./pthread1; done A much smaller test-case. So it seems pthread_cancel does not work reliably on MacOS. Cheers, Bill
/* Copyright (C) 2013 The PARI group.
This file is part of the PARI/GP package.
PARI/GP is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version. It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY WHATSOEVER.
Check the License for details. You should have received a copy of it, along
with the package; see the file 'COPYING'. If not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
struct mt_queue
{
pthread_cond_t cond;
pthread_mutex_t mut;
};
struct mt_pstate
{
pthread_t *th;
void **pth;
struct mt_queue *mq;
long n;
};
static void
mt_queue_unlock(void *arg)
{ pthread_mutex_unlock((pthread_mutex_t*) arg); }
static void*
mt_queue_run(void *arg)
{
void *args = *((void **) arg);
struct mt_queue *mq = (struct mt_queue *) args;
pthread_mutex_lock(&mq->mut);
pthread_cleanup_push(mt_queue_unlock, &mq->mut);
while(1)
pthread_cond_wait(&mq->cond, &mq->mut);
pthread_cleanup_pop(1);
return NULL;
}
void
mt_queue_reset(struct mt_pstate *mt)
{
long i;
for (i=0; i<mt->n; i++)
pthread_cancel(mt->th[i]);
for (i=0; i<mt->n; i++)
pthread_join(mt->th[i],NULL);
for (i=0;i<mt->n;i++)
{
struct mt_queue *mq = mt->mq+i;
pthread_cond_destroy(&mq->cond);
pthread_mutex_destroy(&mq->mut);
}
free(mt->mq);
free(mt->pth);
free(mt->th);
free(mt);
}
struct mt_pstate *
mt_queue_start_lim(long lim)
{
struct mt_pstate *mt =
(struct mt_pstate*) malloc(sizeof(struct mt_pstate));
long i;
mt->mq = (struct mt_queue *) malloc(sizeof(*mt->mq)*lim);
mt->th = (pthread_t *) malloc(sizeof(*mt->th)*lim);
mt->pth = (void **) malloc(sizeof(*mt->pth)*lim);
mt->n = lim;
for (i=0;i<lim;i++)
{
struct mt_queue *mq = mt->mq+i;
pthread_cond_init(&mq->cond,NULL);
pthread_mutex_init(&mq->mut,NULL);
mt->pth[i] = (void*)mq;
}
for (i=0;i<lim;i++)
pthread_create(&mt->th[i],NULL, &mt_queue_run, &mt->pth[i]);
return mt;
}
int
main(void)
{
struct mt_pstate *mt = mt_queue_start_lim(20);
mt_queue_reset(mt);
printf("Done!\n");
}