Gaspard, just a couple of comments.
I'm working on a similar soft-realtime application (autonomous drive of 
a vehicle), and I implemented the high level logic as a Ruby 
statemachine. I found that I can get a satisfying level of realtime 
(including UDP stack access) by keeping a fixed pace loop like that:

while running do
    slp_thr = Thread.start do sleep timestep end
    #do the loop stuff here
    slp_thr.join
end

It works surprisingly fine until 300-350 Hz.
Since you're running on Macs, you could also use the scheduling control 
functions of the Mach kernel. For example, something like that can be 
helpful:

inline do |builder|
    builder.include "<mach/mach_init.h>"
    builder.include "<mach/thread_policy.h>"
    builder.include "<sched.h>"
    builder.c '
      int set_realtime(double period, double computation, double 
constraint) {
          uint32_t HZ = 2000000000;
          struct thread_time_constraint_policy ttcpolicy;
          int ret;
          ttcpolicy.period=HZ*period; // HZ/160
          ttcpolicy.computation=HZ*computation; // HZ/3300;
          ttcpolicy.constraint=HZ*constraint; // HZ/2200;
          ttcpolicy.preemptible=1;

          if ((ret=thread_policy_set(mach_thread_self(),
              THREAD_TIME_CONSTRAINT_POLICY, 
(thread_policy_t)&ttcpolicy,
              THREAD_TIME_CONSTRAINT_POLICY_COUNT)) != KERN_SUCCESS) {
                  fprintf(stderr, "set_realtime() failed.\n");
                  return 0;
          }
          return 1;
      }

      '
end

Cheers,
Paolo
-- 
Posted via http://www.ruby-forum.com/.