0

Is there any way to create two SCHED_DEADLINE threads with a specific offset (phase) to a global cycle? I am trying to create two threads, both with a period of 10 ms, but with an offset of 5ms between their arrival times. The behaviour should look like this, with | being the arrival time, x the actual start time and D being the absolute deadline. Both threads are independent, so there is no need to synchronize them using mutexes etc. They just need the time offset.

Thread 1 |-----xooooo---------D-------------|

Thread 2 ------------------|-----xoooo--D-----

Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
rkl
  • 1
  • 1
  • 1
    "Both threads have a timing dependency and I need to synchronize their offset to a global cycle. Both threads are independent, so there is no need to synchronize them."? – Brendan Feb 06 '20 at 22:56
  • I'm sorry, I mean, that they don't share resources, so there is no need for mutexes etc. – rkl Feb 06 '20 at 23:14
  • I don't think Linux gives you that level of control over thread scheduling (Xenomai does, if you're into that). However, if your goal is to have thread 1's code never run at the same time as thread 2's code, the easy way to obtain that behavior would be to get rid of thread 2 and just run all of the code in thread 1 only. – Jeremy Friesner Feb 07 '20 at 00:47
  • Create two threads, have them both wait on some condition variable. After wakeup, have thread-1 run immediately.. and have thread-2 sleep 5ms.. Now broadcast the condition variable so that both threads wake up and one thread is 5ms off from the other.. with each task being 10ms long it should stay in phase.. I guess.. That's the closest I can imagine.. The real question is why you need this.. – Brandon Feb 07 '20 at 00:51
  • How about two semaphores? Each thread acquires its semaphore at the top of its loop. A third thread (or a timer) alternately releases one or the other of the two semaphores, every 5ms. – Solomon Slow Feb 07 '20 at 01:38

1 Answers1

0

Maybe you can use timer_create() with timer_settime().

olyuboch
  • 3
  • 6