DragonFly bugs List (threaded) for 2009-04
DragonFly BSD
DragonFly bugs List (threaded) for 2009-04
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

[issue1331] [PATCH] libthread_xu: fix problem with umtx errno override


From: "Alex Hornung \(via DragonFly issue tracker\)" <sinknull@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 23 Apr 2009 12:40:17 +0000

Alex Hornung <ahornung@gmail.com> added the comment:

Attached is a test case. Before the fix, when using an argument of 100 or so and
trying a few times, one will see one or more "thread tester error: Device busy".
This Device Busy comes from umtx and not readdir.
After applying the patch that error doesn't occur anymore.

_____________________________________________________
DragonFly issue tracker <bugs@lists.dragonflybsd.org>
<http://bugs.dragonflybsd.org/issue1331>
_____________________________________________________
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>

pthread_barrier_t bar;


void* tester(void *arg)
{
	struct dirent *en;
	DIR *d = opendir("/");

	pthread_barrier_wait(&bar);

	while ( (en = readdir(d)) != NULL )
	{
		if (errno != 0)
		{
			perror("thread tester error");
			break;
		}
	}

	if (!en)
	{
		if (errno != 0)
		{
			perror("thread tester error");

		}
	}
	
}

void* checker(void *arg)
{
	pthread_barrier_wait(&bar);
	printf("Passed barrier!\n");
}


int main(int argc, char *argv[])
{
	int i, ret, nthreads;
	pthread_t th;

	if (argc <= 1)
	{
		printf("Need one argument\n");
		exit(1);
	}

	nthreads = atoi(argv[1]);
	
	printf("Trying with %d threads\n", nthreads);	

	if ( (ret = pthread_barrier_init(&bar, NULL, nthreads)) != 0)
	{
		printf("error occured during pthread_barrier_init, ret = %d\n", ret);
		perror("Or: ");
		exit(1);
	}

	printf("Creating checker thread\n");
	pthread_create(&th, NULL, checker, NULL);

	printf("Creating tester threads\n");


	for (i = 0; i < nthreads; i++)
		pthread_create(&th, NULL, tester, NULL);

	for (;;)
	{
		sleep(1000);
	}

	return 0;
}


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