Hi all!
I'm working on a prog that uses mutexes. Since the code is growing bigger and bigger i decided to split it across multiple C and H files. To my surprise the mutexes stopped working!
I have no idea why this happened.
The general idea of the code is this:
A function that receives the mutex in its argument:
The code that calls the function:Code:void function(pthread_mutex_t mut) { pthread_mutex_lock(&mut); printf("This shows up if function is in the same source file as the calling code."); pthread_mutex_unlock(&mut); }
Sample Makefile:Code:pthread_mutex_t mut; pthread_mutex_init(&mut, NULL); pthread_mutex_lock(&mut); printf("This shows up!"); pthread_mutex_unlock(&mut); function(mut); pthread_mutex_destroy(&mut);
Does anyone have any idea why this happens, and how to solve it?Code:CC = gcc CFLAGS = -Wall -ansi -pedantic -g -D _XOPEN_SOURCE=600 OBJECTS = main.o function.o all: $(OBJECTS) $(CC) $(CFLAGS) -lpthread -lrt -lm -o main $(OBJECTS) main.o: main.c main.h function.o: function.c function.h clean: rm -f *.o main
Thank you!



LinkBack URL
About LinkBacks



