Making a timer go off at a specific time in a C++ process for purposes of synchronizing two processes

148 Views Asked by At

I have two processes in C++ (these are not parent and child processes). Each has been pinned to a specific core using taskset. So, for instance, process 1 is pinned to core 0 and process 2 is pinned to core 1. I want to start running them at the same exact time (with microsecond accuracy).

timer_create allows some code to execute with a specified frequency. However, it doesn't provide a mechanism for it to start at a specific time. What would be the best way to configure a start time such that a section of code in both processes starts off at that particular time, and then repeats with a certain frequency?

1

There are 1 best solutions below

0
On

best ways are going to be very system and os dependent. The best somewhat generic way I can think of is to block both tasks on a counting semaphore, and use a third task to wait on a timer and trigger the semaphore at the desired rate. the degree of precision you want will be difficult if not using a rtos.