'How to create a thread, make it wait for input and then finally have it execute it's function

I have program and I want it to create a thread, thread 'a', I want it to wait for input from a file to be read into a buffer, buffer 1, then execute its function and put the answer to that question in a second buffer, buffer 2. At the moment the thread waits but it never executes and I can't figure out why. Could it be that the parent thread is exiting before thread 'a' has a chance to execute? If this is the case how do I stop the parent thread from exiting? If it is not the case could I have some pointers on what I am doing wrong The code is below.

EDIT: This is a homework assignment and it has to be done in this manner as opposed to reading in the input first or having the thread read the input.

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "LinkedList.h"
#include "macros.h"
#include "FileReading.h"

pthread_mutex_t lock;
pthread_cond_t cond;

int returnSeekTime(int curData, int nextData)
{
    int seekTime;

    if (curData > nextData)
    {
        seekTime = curData - nextData;
    }
    else
    {
        seekTime = nextData - curData;
    }
    return seekTime;
}

void* firstComeFirstServed(void* data)
{
    Buffers* buffers = (Buffers*)data;
    Buffer1 buffer1 = buffers->buffer1;
    Buffer2 buffer2 = buffers->buffer2;
    int curData, nextData;
    Node* current = current = buffer1.disks->head;

    pthread_cond_wait(&cond, &lock);
    buffer2.seekTime += returnSeekTime(buffer1.secondDisk, current->data);


    while(current != NULL && current != buffer1.disks->tail)
    {
        curData = current->data;
        nextData = current->next->data;

        buffer2.seekTime += returnSeekTime(curData, nextData);
        current = current->next;
    }

    return NULL;
}

int main (void)
{
    char fileName[11] = "input.txt\0";
    pthread_t a;
    Buffers* buffers = (Buffers*)malloc(sizeof(Buffers));
    buffers->buffer1.disks = createLinkedList();
    
    pthread_create(&a, NULL, firstComeFirstServed, (void*)buffers);
    readInputFile(fileName, &buffers->buffer1);
    pthread_cond_signal(&cond);
    pthread_mutex_unlock(&lock);

    
    
    return 0;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source