Mutex lock timeout without an RTC

Hey guys,

I’m writing some code on a Digi Connect ME 9210 using multiple threads with shared resources. Recursive mutexes are being used to protect said resources, however I’ve been having some problems synchronizing with multiple threads.

I’d like to implement a timed lock on the mutexes using pthread_mutex_timedlock, but this only takes an absolute time. I read here that without a RTC, time is based off the system clock. So I tried to implement this with the following code:

struct timespec curTime;
clock_gettime(CLOCK_MONOTONIC, &curTime);
abstime->tv_sec += curTime;

pthread_mutex_timedlock(_Lock, abstime);

Where both _Lock and abstime have been previously defined. abstime is a pointer to a struct timespec containing the desired offset till timeout, and _Lock is my mutex. Both CLOCK_MONOTONIC and time(NULL) are returning the same number of seconds, so I figured both were being based off the system clock.

One thread is continuously locking and unlocking the mutex as it carries out its functionality, but I need a second thread to be able to change a parameter used by the first thread. The issue I’m having is that this code isn’t timing out when it should (as I’m setting abstime to one second), and the command is remaining blocked for a long period of time. What am I doing wrong exactly, and is there a better way to use a timed lock with this architecture? Is there any way to do a relative timed lock instead of basing it off the clock?