Dear All,
This is a borderline question, but I figured darwin-kernel was the most suited list. Please feel free to recommend any other list you deem more appropriate.
I just finished upgrading a cocoa data acquisition from non-ARC, C++, Obj-C, OS X 10.8 to ARC, C++, Obj-C, Swift, OS X 10.10. At the heart of the application are blocks dispatched on a serial queue. Some are short-lived and perform simple tasks like mechanical parts actuation, hardware initialization, etc… other are long-lived (several days / weeks) and perform data acquisition.
Data acquisition consists in interrogating devices connected to a MacBook Pro (mid 2012) through RS-485 (FTDI chip) every second. I have implemented the synchronization this way :
1. Get mach_absolute_time() (→start) 2. Query all instruments to get the data 3. Get mach_absolute_time() (→end) 4. usleep() for 1s + start – end
Actual implementation uses nanoseconds or microseconds when appropriate and requires a call to mach_timebase_info(). I am aware there may be “better” options such as using a dispatch source but the accuracy I get this way is more than satisfactory (better than 100 µs) and this design allows me to focus on the “block” design, to build scientific experiments.
The issue I would like to discuss is that after a certain time, my app goes from taking one measurement every second (give or take a maximum of 50 µs) to taking one measurement every 41.000000 seconds exactly.
This happens when the screen saver starts or when the display goes to sleep and only on 10.10, not on 10.8. I can’t test 10.9 for now. The computer is configured not to sleep (Energy Saver preferences). When either Display sleep (Energy Saver preferences) and/or the screen saver (Desktop & screen saver preferences) are triggered, measurements periods increase from 1 s ± 50 µs to 21 s ± 50 µs (for about 10-15 s) then to 41.000000 s for hours with exceptional periods of 600-700 s.
I know that minor “imprecisions” come with using sleep(), but 41 seconds is that’s beyond imprecise. So, what’s different about 10.10? How can I reliably sleep for 500 – 800 ms without burning the screen (I am planning a 9000 hours long experiment).
Best regards, Jean
-----------Jean Suisse Institut de Chimie Moléculaire de l’Université de Bourgogne (ICMUB) — UMR 6302
|