Skip to content

Instantly share code, notes, and snippets.

@tosiara
Created October 27, 2019 18:17
Show Gist options
  • Save tosiara/3c9739744b6dd17d8f1ea3c0d99d8b9d to your computer and use it in GitHub Desktop.
Save tosiara/3c9739744b6dd17d8f1ea3c0d99d8b9d to your computer and use it in GitHub Desktop.
threads.c
#include <pthread.h>
#include <stdlib.h>
void *payload()
{
while (1);
}
void main(int argc, char **argv)
{
int threads = 1;
int counter;
if (argc > 1)
threads = atoi (argv[1]);
pthread_t *t;
t = (pthread_t *)malloc (sizeof(pthread_t) * threads);
for (counter = 0; counter < threads; counter++)
pthread_create(&t[counter], NULL, &payload, NULL);
for (counter = 0; counter < threads; counter++)
pthread_join(t[counter], NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment