/* tfifo.c David Rowe Nov 19 2012 Takes FIFOs, in particular thread safety. */ #include #include #include #include "fifo.h" #define FIFO_SZ 1024 #define WRITE_SZ 10 #define READ_SZ 8 #define N_MAX 100 #define LOOPS 1000000 int run_thread = 1; struct FIFO *f; void writer(void); void *writer_thread(void *data); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; #define USE_THREADS //#define USE_MUTEX int main() { pthread_t awriter_thread; int i,j; short read_buf[READ_SZ]; int n_out = 0; int sucess; f = fifo_create(FIFO_SZ); #ifdef USE_THREADS pthread_create(&awriter_thread, NULL, writer_thread, NULL); #endif for(i=0; i WRITE_SZ) { for(i=0; i