I have a thread question:

I want to build a I/O device and write some windows to control it. For the short term, i plan on using the WinIO to deal with the dirty work of VxD's/WDM's.

I plan to have a button to "Start Capturing" which would begin to poll the IO port (for a given period of time ~ 2 sec max).

I realize windows is event driven, and that a normal window would be suspended from time to time. However, while im polling the port, i dont want to be interupted, or have the process switch to another.

Is there a clean way of setting this up before i start the poll (after a button click), and then restoring normal priority to the process thread afterwards (when it times out)?

Or should i get into a creating a separate thread for this purpose? (I dont play around in these parts much ;) )


I think i can do what i want, cause my scanner does this: all running processes are ignorred until finished. Im hoping this "feature" is not written into its driver tho :rolleyes:


Thanx for any advice or help you can provide..
Posted on 2002-07-06 03:55:16 by NaN
Look at the SetPriorityClass and SetThreadPriority API's. Try SetPriorityClass with REALTIME_PRIORITY_CLASS, that should shut out EVERY other thread, including operating system threads. You may want to be careful with writing data to disk:

(Quote from MSDN SetPriorityClass)

Specify this class for a process that has the highest possible priority. The threads of the process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive.
Posted on 2002-07-06 04:08:41 by Qweerdy
Try checking out the Critical Section Objects. InitializeCriticalSection, EnterCriticalSection, LeaveCriticalSection ...

oh shoot! it's nearly 3 in the morning ... need some sleep ... I'll post some sources later. :grin:
Posted on 2002-07-06 04:48:17 by stryker
stryker, AFAIK Critical sections only work in the same process. In fact, MSDN CreateCriticalSection says:

For similar synchronization between the threads of different processes, use a mutex object.

However, using a mutex requires some code in the other process(es), so perhaps not very usefull for exclusive execution.
Posted on 2002-07-06 05:54:53 by Qweerdy
Setting process and thread priorities to realtime does help a lot
(and you better be careful what you do when you mess with this ;)).
It's probably a good idea to create a separate thread for the grabbing
(polling ick, you really ought to code something interrupt-based...
but then I'm afraid there's no way around writing a driver).
You could create the thread at app start, and have it wait on an
event object - the advantage of using event objects instead of a
"cmp , 1" loop is that your thread is not scheduled
while it's waiting...

Hm, that blob sounds pretty incoherent but oh well :)
Posted on 2002-07-06 09:17:05 by f0dder
Using SetPriorityClass does not guarantee that your thread will not be interrupted. Instead, write a VxD, which is the preferred way of supplying device drivers, and disable interrupts. Disabling interrupts for a long time should be done sparingly, though.
Posted on 2002-07-06 09:45:08 by Sephiroth3
oops my mistake :) I've never really read the whole thing from PSDK, I just used it directly without knowing this. :)
Posted on 2002-07-06 09:55:17 by stryker
Hey Nan,
This article explains synchronization between user mode and kernel mode better then I can. Its in C++ but is very informitive.

Hope This Helps

Posted on 2002-07-06 12:44:17 by prs
Thanx all for you thoughts.. i will have to sift thru them and see what is best... Im hoping in the short term to avoid a Vxd or Wdm, cause i dont want to waste more than a day or so... (im the midst of a paying project ;) ). In the long term i would definitely use a driver for better accuracy... (thanx for the link prs).

If anyone has any more advice.. im always open to a new idea... :alright:

As background, im building a Logic Analyser for my laptop.. I do alot of PIC programming these days, and its bloody hell trying to see "data packets" of 1's and 0's in short spurts on an oscilloscope... This means debugging the PIC assembly is more like theoretical physics then it is coding.. (you get no *real* feedback on what is really going on inside the chip)..

So i plan to use the parallel port to give me 8 - 1 bit probes to see how the logic is changing... And have a windows program ready to capture data in "real time", for a set period of time...

A good example would be a bus protocol.. I reciently wrote a bus tranciever and its hard to verify your code if the bus itself is 98% scilent and only active hen you press a button!! (this is a fast 'blip' on the scope, hardly useful). It would be nice to press the space bar to start capture for 2 seconds, then start the PIC up with a test scenario, and see what the 'blip' gives you... ;)

Anyways.. thanx again so far for you suggestions!
Posted on 2002-07-07 00:42:53 by NaN
I think that if i understand correctly what your
doing then this tool would probably be
very helpfull. again hope this helps


works on 9x on nt and includes source.

Posted on 2002-07-07 12:42:00 by prs
Again.. thanx for the link... lots of good info here.. like registry paths and API's to look up, relivent to my goal here..

I downloaded the tool.. as it sounds good, its more of a driver debugger.. and if i dont have the egg, there is no point looking for chickens ;)

However, thanx again!
Posted on 2002-07-07 22:50:29 by NaN