In my application written in C language I have two threads:
The first thread contains a UDP listener used for Interprocess Communication for signalling purposes. When a signal arrives to this thread, it tries to lock the second thread using pthread_mutex_lock
to execute some functions and after that it unlocks it, and the second thread continues it normal execution.
I noticed that locking the thread consumes too much time for example around 100 ms, which is too much. But sometimes it consumes not much around 10 ms which is OK for me.
So can anyone tell me what is happening, why I am getting that much of time variation in my executable code? Is there any better way to achieve what I am doing in a better way i.e. locking and unlocking?
Note: I am running my application in a Virtual Machine with Linux Ubuntu x64 bit, with 2GB ram and 2 CPUs, the final output is in release mode.