

Ask HN: What are the language/OS choices for low-latency - majidfn

Hello,<p>For purpose of an academic research, I need your inputs on implementing the following software so I can give better recommendations to a friend.<p>The software will display images in frequencies ( Images are flickering between the image itself and a black screen). 
When an image is shown a trigger will be sent to an external device, and another trigger will be sent when the image is no longer visible (black screen appears).<p>The frequency of images is about 50Hz, meaning that for 20ms an image is shown, and for 20ms the black screen is shown.<p>The synchronization between the code, the visual output of the images and trigger sent to device is very important, it should be as close as possible to real-time. (&lt;5ms delay).<p>(For the moment we are not bringing the latency of the external device in to account)<p>As this is a research project, choices of the tech would highly impact the results.<p>So far the options for the language are:<p>- C<p>- C#<p>- Matlab (and external toolboxes or Matlab’s realtime workshop)<p>- Python (and external libraries)<p>1 - Considering the performance, development time, availability of external libraries, etc.  which of the above languages you choose to implement the system, and why?<p>(Python and Matlab are preferable because ease of use and faster development, but doubtful about the required low latency)<p>2 - What would be your pick for the OS for such software? Which allows the software to have a high priority execution thread. An OS with low latency. 
(Probably a RTOS, Real Time Operating System, is not needed)<p>Any opinion is much appreciated.
======
ivantung
You don't need anything fancy here. Coming from the game industry where frame
updates are typically targeted at 60 Hz or 16.66 ms per frame. Even mobile
games often target 60Hz. During the 16ms a game typically has to do a lot of
stuff such as ai, rendering, user input. So in comparison your needs are very
light. You can probably develop what you need in any number of languages and
OS. I would go with what is you are comfortable with. Take a look at SDL2, you
could probably put together something in one day. The only thing unusual you
mentioned is the external triggering mechanism. Whatever this is you will need
some kind of device API/interfacing code, so this may decide which OS you will
need to use. SDL2 is cross platform so you should be good to go there.

------
yetihehe
Maybe you don't need to do it in software? If you get LCD with LED backlight,
you can turn it on and off from arduino or even external device itself. It
would have nanoseconds of latency (it depends on length of cables now). If you
need software solution I would propose C/C++ and linux, if you use library
which handles high resolution timers, it's rather easy to achieve sub 1ms
latency.

~~~
majidfn
Thanks for your thoughts. The issue is user should be able to interact with
the system. For example after viewing the flickering image for couple of
seconds, user should make a choice and click/touch.

~~~
yetihehe
Then combined solution, arduino can be connected to computer and when someone
clicks, arduino stops blinking image and notifies program, which does what it
needs. Then when program is ready to blink another image, it shows blank
screen, notifies arduino to start blinking again and then shows image. Cycle
repeats. If you need better responses, you should provide more data about what
is required, what you need to measure.

