Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use a thread to asynchronously access my device connected to the PCI bus?

I have a piece of hardware that is connected to my PC via the PCI bus. I am accessing the hardware through a .NET wrapper around the device driver.

I do not have any specifications on how the device is performing PCI-wise. Which brings me to my first question.

1) Are devices connected through PCI guaranteed to deliver data at a certain speed?

2) When communicating with the device, I would like my UI to stay responsive. Is it a good idea to kick off communication with the device in a (threadpool) thread, or is the overhead associated with this too large compared to how fast accessing the PCI bus is?

Edit:
Question rewritten. Reflected too much the end of a long work day.
Removed the requirement for the thread to be a thread pool thread.

like image 624
kasperhj Avatar asked Jan 14 '23 07:01

kasperhj


1 Answers

In general, any time you have the opportunity to write code without thread affinity, it's often a good idea to do so. That way you have the freedom to switch off the UI thread when and if it becomes a responsiveness problem. Designing your API for this I/O using Async methods also keeps your options open going forward in a good way.

Whether the thread you're on is a threadpool thread or one you spawn yourself seems irrelevant if you don't have to occupy it for long periods of time. And if you can do Async I/O then a threadpool thread should be fine.

like image 60
Andrew Arnott Avatar answered Jan 20 '23 16:01

Andrew Arnott