All pastes #10761 Raw Edit

pthread

public c v1 · immutable
#10761 ·published 2005-05-02 13:26 UTC
rendered paste body
#include <pthread.h>#include <unistd.h>#include <stdio.h>void *child(void *arg);struct thread_data{    int amount;    int period;    int iterations;};/* create a new thread that allocates memoryreturns the new process id */int start_periodic(int amount, int period, int iterations) {    pthread_t tid;        struct thread_data args;    args.amount = amount;    args.period = period;    args.iterations = iterations;    if (pthread_create(&tid, NULL, child, &args) != 0) {        /* error creating child, to stderr */    }    printf("created child: %d\n", tid);    return 1;    }void *child(void *arg) {    struct thread_data * my_data;    my_data = (struct thread_data *) arg;        int period = *my_data.period;    int amount = *my_data.amount;    int iterations = *my_data.iterations;    return arg;}