threads.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:50:39 +0200
changeset 72 4103c76d5bf2
parent 27 81a574d60c15
child 77 49e0babccb23
permissions -rw-r--r--
sort.c: bubblesort fixed * the bubblesort algorithm has an abort-condition * the linearsort algorithm has not an abort-condition committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/threads.c
 * Copyright (C) 2008 Markus Broeker
 */

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>

void do_some_work (void)
{
    time_t start_time = time (NULL);

    while (time (NULL) == start_time);  /* busy-wait for 0-1 seconds */
}

void *thread_func (void *vptr_args)
{
    int i;

    for (i = 0; i < 20; ++i) {
        fprintf (stderr, "  b\n");

        do_some_work ();
    }
    return NULL;
}

int main (int argc, char **argv)
{
    int i;

    pthread_t thread;

    pthread_create (&thread, NULL, &thread_func, NULL);

    for (i = 0; i < 20; ++i) {
        fprintf (stdout, "a\n");

        do_some_work ();
    }

    pthread_join (thread, NULL);

    return EXIT_SUCCESS;
}