[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Opening a device driver from multiple application.

I'm just curious if opening the same device driver from multiple part of the program is  considered as bad practice. So let say I have a multi threaded program which operate on the same driver. Each thread open a device descriptor to the driver and read/write to it independent of each other. Would it worth the effort to recode so we open the device once, and get all the thread to use the same descriptor?
0
1ce
Asked:
1ce
1 Solution
 
brettmjohnsonCommented:
As long as the device driver is reentrant and allows multiple opens, it should not
be a problem.  Consider the disk driver.  Multiple programs and multiple threads
within the same program can open files without a problem and it is indeed considered
good practice.  Some devices (such as scanners) might not allow themselves to be opened
by more than one thread or process at a time.


0
 
Karl Heinz KremerCommented:
What device are we talking about?

I don't think that the disk driver is a good example for this: You are usually not working with the disk driver directly - your program uses the read/write operations that are provided by the system library, which in turn call the read/write system calls provided by the operating system. Only the OS is then using the disk driver. So, your multiple read/writes (or open/closes) will very likely be converted to sequential events that are sent to the disk driver.
0
 
mishagaleCommented:
As mentioned above, it probably depends on the driver, but also on just how much you use it. If you have very large numbers of open file descriptors, then it might give better performance to just use one shared FD. If you're talking about opening it two or three times, I doubt there would be a problem.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now