Ticket #144 (new defect)

Opened 4 years ago

libusb_close() does not block until all submitted transfers have completed

Reported by: stuge Owned by:
Milestone: Component: libusb-1.0
Keywords: Cc:
Blocked By: Blocks:


Quoting http://marc.info/?m=134331313730019

The C library does not cancel transfers when libusb_close() is
called, and on the other hand libusb_close() does not wait until all
transfers have been completed but closes the device immediately - so
the transfers will never complete. The application has to clean up
all transfers before calling libusb_close().

When using the synchronous API there's no way to cancel a transfer.

There are two major alternatives, both of which have been discussed a
few times before:

1. Application does not call libusb_close() until after all
   synchronous transfers have completed

1a. Application uses synchronous API and keeps one internal state to
    indicate need to wait for all transfers to finish, and only then
    continue to call libusb_close().
1b. Application uses asynchronous API and cancels all transfers on
    exit, and waits until they have all completed. Same internal
    state is neccessary as in 1a.

2. libusb_close() does not return until all transfers have completed.

2a. libusb_close() simply blocks until all transfers have completed.

2b. libusb_close() first cancels all transfers, and then blocks.

2b. will finish quicker but also requires some internal changes in
libusb. 2a. would be simpler to implement.

In my opinion the current behavior of libusb_close() could be said to
be buggy, and I would like libusb to either do 2a or 2b. There was a
bit of discussion, but no patch.

Change History

Note: See TracTickets for help on using tickets.