[linux-l] Debian-Mirror der belug...

Jan-Benedict Glaw jbglaw at lug-owl.de
Fr Okt 17 18:04:08 CEST 2003


On Fri, 2003-10-17 10:27:23 +0200, Tobias Schlottke <toby at schlottke.net>
wrote in message <Pine.LNX.4.56.0310171022010.3502 at ws-toby.Netzwert.AG>:
> 
> Test1:
> sam:monasemu> uname -a;java -version;java MakeThreads
> Linux sam 2.4.22Toby2 #2 SMP Thu Sep 25 14:57:46 CEST 2003 i686 Intel(R) Pentium(R) 4 CPU 2.40GHz GenuineIntel GNU/Linux
> java version "1.4.1_04"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_04-b01)
> Java HotSpot(TM) Client VM (build 1.4.1_04-b01, mixed mode)
> 
> Test done in 224 ms

jbglaw at min:~$ gcc threadtest.c -lpthread	# Mit locking
jbglaw at min:~$ ./a.out 
Zeit: 3.726832 sec
jbglaw at min:~$ ./a.out 
Zeit: 3.493854 sec
jbglaw at min:~$ ./a.out 
Zeit: 3.474669 sec
jbglaw at min:~$ ./a.out 
Zeit: 3.525251 sec
jbglaw at min:~$ ./a.out 
Zeit: 3.346469 sec
jbglaw at min:~$ ./a.out 
Zeit: 3.545781 sec

System: 2.4.19-pre7, P3 Katmai, 500MHz, 512KB Cache.

MfG, JBG


#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>

#define THREADS 1000

#define WITH_LOCKING

#ifndef WITH_LOCKING
#define pthread_mutex_lock(x)	0
#define pthread_mutex_unlock(x)	0
#endif



static int threads_started = 0;
static pthread_mutex_t counter_mutex;

void *
run (void *dummy)
{
	if (pthread_mutex_lock (&counter_mutex)) {
		perror ("pthread_mutex_lock ()");
		exit (EXIT_FAILURE);
	}
	threads_started++;
	if (pthread_mutex_unlock (&counter_mutex)) {
		perror ("pthread_mutex_unlock ()");
		exit (EXIT_FAILURE);
	}

	sleep (30);
}

int
main (int argc, char *argv[])
{
	int i;
	struct timeval t1, t2, diff;
	pthread_t thread;

	/* Init mutex */
	if (pthread_mutex_init (&counter_mutex, NULL)) {
		perror ("pthread_mutex_init ()");
		exit (EXIT_FAILURE);
	}

	/* Get start time */
	if (gettimeofday (&t1, NULL)) {
		perror ("gettimeofday () - first call");
		exit (EXIT_FAILURE);
	}

	/* Start threads */
	for (i = 0; i < THREADS; i++) {
		if (pthread_create (&thread, NULL, &run, NULL)) {
			perror ("pthread_create ()");
			fprintf (stderr, "...at thread #%d\n", i);
			exit (EXIT_FAILURE);
		}
		if (pthread_detach (thread)) {
			perror ("pthread_detach ()");
			fprintf (stderr, "...at thread #%d\n", i);
		}
	}

	while (1) {
		usleep (2000);
		if (pthread_mutex_lock (&counter_mutex)) {
			perror ("main: pthread_mutex_lock ()");
			exit (EXIT_FAILURE);
		}
		if (threads_started == THREADS) {
			(void) pthread_mutex_unlock (&counter_mutex);
			break;
		}
		if (pthread_mutex_unlock (&counter_mutex)) {
			perror ("main: pthread_mutex_unlock ()");
			exit (EXIT_FAILURE);
		}
	}

	if (gettimeofday (&t2, NULL)) {
		perror ("gettimeofday () - second call");
		exit (EXIT_FAILURE);
	}

	timersub (&t2, &t1, &diff);
	printf ("Zeit: %d.%06d sec\n", diff.tv_sec, diff.tv_usec);

	return EXIT_SUCCESS;
}

-- 
   Jan-Benedict Glaw       jbglaw at lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname   : nicht verfügbar
Dateityp    : application/pgp-signature
Dateigröße  : 189 bytes
Beschreibung: nicht verfügbar
URL         : <https://mlists.in-berlin.de/pipermail/linux-l-mlists.in-berlin.de/attachments/20031017/e99fb338/attachment.sig>


Mehr Informationen über die Mailingliste linux-l