#!/usr/bin/bash
###SHELLPACK preamble poundsyscall 0

###SHELLPACK parseargBegin
###SHELLPACK parseargEnd

###SHELLPACK self_extract pound_syscall.c 

mkdir $SHELLPACK_SOURCES/poundsyscall-${VERSION}-installed
for FILE in pound_syscall.c; do
	mv $SHELLPACK_TEMP/${FILE} $SHELLPACK_SOURCES/poundsyscall-${VERSION}-installed/${FILE} ||
		die Failed to move ${FILE} into install directory
done

echo poundsyscall installed successfully
exit $SHELLPACK_SUCCESS

# Programs based on those posted to "lockless sys_times and posix_cpu_clock_get"
==== BEGIN pound_syscall.c ====
#include <stdio.h>
#include <pthread.h>
#include <sys/times.h>
#include <sys/types.h>
#include <unistd.h>

struct tms start;

void *pound (void *threadid)
{
	int i, j = 0;
	for (i = 0; i < 50000000 / NUM_THREADS; i++) {
		j += (int)getppid();
	}
	pthread_exit(NULL);
}

int main()
{
	pthread_t th[NUM_THREADS];
	long i;
	times(&start);
	for (i = 0; i < NUM_THREADS; i++) {
		pthread_create (&th[i], NULL, pound, (void *)i);
	}
	pthread_exit(NULL);
	return 0;
}
==== END pound_syscall.c ====
