Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Generates load over multiple cores.
/*
* load.c: Generate massive load (not really) across multiple cores.
*
* Compile with:
* gcc load.c -lpthread -W -Wall -Werror -O3 -march=native -mtune=native \
* -Wl,-O3 -s -pipe
*
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
static pthread_t *threads;
static void
*generate_load(void *ptr)
{
while(1) ptr++;
return NULL;
}
int
main(int argc, char **argv)
{
static int ii;
/* Sanity checks */
if((argc != 2) || (isdigit(atoi(argv[1]))) || (aoit(argv[1] < 1)))
{
fprintf(stderr, "Usage: %s /[0-9]+/\n", argv[0]);
exit(EXIT_FAILURE);
}
threads = calloc(atoi(argv[1]), sizeof(pthread_t));
for(ii = 0; ii < atoi(argv[1]); ii++)
pthread_create(&threads[ii], NULL, generate_load, NULL);
for(ii = 0; ii < atoi(argv[1]); ii++)
pthread_join(threads[ii], NULL);
/* Shouldn't ever even get here. */
free(threads);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.