Nanosleep

Question: Write a function 'nsleep' in C that takes in a q timespan or long argument, and puts the calling thread to sleep for that many nanoseconds.

Example

                                
                                q)\s 
3i 
q)sleep:`sleep 2: (`nsleep;1) / load 'nsleep' from shared library (sleep.so) 
q)sleep 00:00:01n 
0i 
q)\t sleep 1000000000 
1000 
q)\t sleep 00:00:01n 
1000 
q)\t sleep 00:00:00.100n 
100 
q)\t sleep 00:00:00.001n 
1 
q)\t sleep 00:00:01.001n 
1001 
/ can use sleep on multiple threads 
q)\t sleep peach 00:00:01 00:00:01.001 00:00:00.001n 
1001
                                
                            

Solution

Tags:
c functions shared library
Searchable Tags
algorithms api architecture asynchronous c csv data structures dictionaries disk feedhandler finance functions ingestion ipc iterators machine learning math multithreading optimizations realtime shared library sql statistics streaming strings tables temporal utility websockets