|
From: Simone Navari on 4 Jul 2008 03:33 Hi everybody, I written a DLL to interface with a custom PCI device; manufacturer provides me via another DLL some functions to write and read bytes to device and some other to know if board is ready to accept or send data. What I need is to implement a timeout mechanism when my DLL has to wait for some data, I've used timeGetTime function to measure elapsed time from waiting start but if some other heavy processes are running seems that my waiting routine is interrupted and when scheduler gives me the control again a time greater than timeout is elapsed so I return with an error. Is there a better way to do it or the only solution is too increase a lot the timeout I use ? Thanks in advance. Simone Navari
From: Sten Westerback (MVP SDK 2005-6 :) on 4 Jul 2008 04:52 "Simone Navari" <simnav(a)gmail.com> wrote in message news:21b515b9-1afc-4567-a359-b5d831399d48(a)f63g2000hsf.googlegroups.com... > Hi everybody, > > I written a DLL to interface with a custom PCI device; manufacturer > provides me via another DLL some functions to write and read bytes to > device and some other to know if board is ready to accept or send > data. What I need is to implement a timeout mechanism when my DLL has > to wait for some data, I've used timeGetTime function to measure > elapsed time from waiting start but if some other heavy processes are > running seems that my waiting routine is interrupted and when > scheduler gives me the control again a time greater than timeout is > elapsed so I return with an error. Is there a better way to do it or > the only solution is too increase a lot the timeout I use ? There are basically a few things you can do: - set a higher Thread prioroty (and, if other processes load CPU much, also pro cess priority class) - use GetTickCount() as it's the fastest - don't Sleep the whole timeout time but peek more often so you are more likely to get awaken in time - use WaitableTimer's - if there are several CPU's, set the Affinity of as many other processes and threads to all CPU's but one (and fix your thread to one CPU if you dare to not let other CPU's running it) - ask manifacurer to add an API that either let you read cached data (ReadFile) or register an event that the driver signals when data is available But in any case there is no guarantee that the scheduler will give your thread CPU time exactly when you tell it. If your poll need to be "too frequent" the driver should support buffered I/O. - Sten
|
Pages: 1 Prev: User Defined Resource? Next: How to know when user use task switching |