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

/* global variable for compare and exchange */
pthread_mutex_t CE_MUTEX;		// compare and exchange

/* Node and Queue structure */
typedef struct NODE {
	void *val;
	struct NODE *next;
} Node;

typedef struct LOCKFREEQUEUE {
	Node *head, *tail;
} LockFreeQueue;

typedef struct TWOSTRINGS {
	char *first;
	char *second;
} TwoStrings;

/* function prototype */
Node *NewNode(void *init_val);
LockFreeQueue *NewLockFreeQueue();

void InitCE (pthread_mutex_t *ce_lock);
void DestroyCE (pthread_mutex_t *ce_lock);
int CompareAndExchange (void **destination, void *value, void *comparand);

void LockFreeQueue_enq(void *x);
void *LockFreeQueue_deq();

void LockFreeQueue_enq_WithError1 (void *x);
void LockFreeQueue_enq_WithError2 (void *x);

void *EnqTwoStrings (void *contain);
void *EnqTwoStrings_WithError1 (void *contain);
void *EnqTwoStrings_WithError2 (void *contain);

void *DeqThreeStrings ();