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

Re: The perl 5.10.0 headache



Hi from GNU/kFreeBSD porter.

After talking it over with stephen and arranging perl 5.10 to be built on
real metal vs aranym, we are pleased to report that perl passes its test
suite with the exception of one test, a threading stress test which launchs multiple threads, and then tries to make sure that they close in order.

It appears its caused by the antique version of glibc we use, and the fact that we are using the old linuxthreads package vs. nptl.

The test passes even under linuxthreads, but real-time variant of
signals have to be used, i.e. they should properly queue in kernel.
I know it, because on GNU/kFreeBSD it needs 7.x kernel.

You can use attached code to perform the same test in C.
Problem would be rather missing memory barier, or non-atomic operation.
This should be fixable even with 2.5 glibc and linuxthreads.

Petr
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>


int x,y;
pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

void * job(void * arg)
{
	int a = (int) arg;

	struct timeval now;
	struct timespec timeout;
	
	int retcode;
	printf("Started %d\n", a);
	usleep((rand() % 32777));

	pthread_mutex_lock(&mut);
	while (x != a) 
        {
        	printf("wait %d %d\n", x, a);
		gettimeofday(&now,NULL);
		timeout.tv_sec = now.tv_sec + 1;
		timeout.tv_nsec = now.tv_usec * 1000;
        	retcode = pthread_cond_timedwait(&cond, &mut, &timeout);
		if (retcode == ETIMEDOUT)
			printf("Timeout %d\n", a);
	}
	
	x++;
        printf("exit a %d %d\n", x, a);
	pthread_cond_broadcast(&cond);
        printf("exit b %d %d\n", x, a);
	pthread_mutex_unlock(&mut);
        printf("exit c %d %d\n", x, a);
}

int main()
{
	pthread_t t;
	int i;
	for (i = 0; i < 50; i++)
		pthread_create(&t, NULL, job, (void *) i);
	sleep (10);
        printf("FINAL %d %d\n", x, i);
	
}

Reply to: