|
From: Ludovic R. <lud...@gm...> - 2010-06-28 09:11:48
|
Hello, I have a problem with my code and I discovered I can reproduce it using only the synchronous API. I use two threads. thread A is calling libusb_interrupt_transfer() thread B is calling libusb_bulk_transfer() for write and read in a endless loop Some times the loop is suspended for 1 minute and then continues. The suspend duration is the duration used in libusb_handle_events() from io.c. If I change the 60s timeout in libusb_handle_events() to 6s timeout my loop is halted for 6s instead of 60s. The loop also continues if the libusb_interrupt_transfer() returns (after an event occurs on my device). It seems the code used in do_sync_bulk_transfer() is not correct if used from two threads at the same time. I use the same context (NULL= default) and the same device (but on two different endpoints) in the two threads. I was wondering why the code in do_sync_bulk_transfer() is so much simpler than the code given in example in "Multi-threaded applications and asynchronous I/O " [1]. [1] also says "libusb is a thread-safe library, but extra considerations must be applied to applications which interact with libusb from multiple threads." And my application uses multiple threads. What should I do? Thanks [1] http://libusb.sourceforge.net/api-1.0/mtasync.html -- Dr. Ludovic Rousseau |