The program (​ stack-ptr.c​ ) implements stack using a linkedlist, however, it contains a race condition and is not appropriatefor a concurrent environment. Using Pthreads mutex locks, fix therace condition. For reference, see Section 7.3.1 of SGGbook.(Section 7.3.1 is about mutex and semaphores it doesexplain how to implement I'm just having a hard time finding therace condition within the code)
/*
* Stack containing race conditions
*/
#include
#include
#include
typedef int value_t;
// Node structure
typedef struct Node
{
value_t data;
struct Node *next;
} StackNode;
// function prototypes
void push(value_t v, StackNode **top, pthread_mutex_t*mutex);
value_t pop(StackNode **top, pthread_mutex_t *mutex);
int is_empty(StackNode *top);
void push(value_t v, StackNode **top, pthread_mutex_t *mutex)
{
StackNode *new_node;
new_node = (StackNode *)malloc(sizeof(StackNode));
 Â
new_node->data = v;
 Â
// mutex lock and unlock code
 Â
}
value_t pop(StackNode **top, pthread_mutex_t *mutex)
{
  StackNode *temp;
 Â
  pthread_mutex_lock(mutex);
 Â
// mutex lock and unlock code based on empty or full stack
 Â
}
int is_empty(StackNode *top) {
if (top == NULL)
return 1;
else
return 0;
}
int main(void)
{
StackNode *top = NULL;
// pthread_mutex variable declarion and verify push/pop operationfor 4 inputs (5, 10, 15, 20)
 Â
  return 0;
}