Input from System Clock

Not sure if I am approaching a project from the wrong direction, but I wonder how the system clock may be used as an input to a Julia program. Say, every 50mS I want a signal (like an interrupt) to start a process. I don’t want the program to check all the time to see if 50mS has passed (because then the program spends a lot of time just checking the time). I would like the program to not do anything until the system clock triggers (or sends an interrupt signal) to the program. I am not sure if I can do that within a Julia program, or if I should approach this from the system side (have the system call the program every 50mS . . .)

More generally, does Julia have access to any of the system interrupts ?

You could simply use a loop and call sleep(0.05) inside it.


: ) okay, sleep may work. I would like to know, then, how sleep actually works. I can test it (. . . later). When it sleeps it releases CPU resources . . . what is the mechanism that wakes it up?

Maybe what I am thinking is a Julia program that runs in the background (and consumes little CPU resources) until a timer calls it to wake up and run.

Create a Timer and wait for it in a Task. You then can let the task call a function at each tick.


A great way to figure this out is using the @edit macro, e.g. @edit sleep(0.05) in the REPL should point you to the implementation. In the case of sleep it’s just calling wait(Timer(0.05)), as @pbayer already pointed out.