# Thread-Specific Data: Example - Thread function.

###

    void start_func(int thread_num)
    {
        char    *buf;

        pthread_setspecific(key1, (void *)thread_num);
        buf = (char *) malloc(100);
        pthread_setspecific(key2, (void *)buf);
        pthread_setspecific(key1, (void *)NULL);
        buf = pthread_getspecific(key2);
        free(buf);
        pthread_setspecific(key2, (void *)NULL);
    }

    void destruct(void *value)
    {
        free(value);
    }

Previous slide | Next slide | Back to first slide | View graphic version