Tim,

If I call the same code with one thread, it works without any problem. so I
believe it has something to do with how libusb work in multi-threading code.


Do you have any sample code how to handle multi-threading for libusb
asynchronous operations? do I need to anything to protect call to
libusb_handle_events_timeout_completed ?  (can
libusb_handle_events_timeout_completed
be call at same time from multiple thread?)
Did I do anything wrong in the loop? anything I am suppose to do I did not
do in code?

I pretty much showed you the whole libusb related code here, the only thing
I did not show is the client, which is very complicated and I am not sure
how it was related to this libusb problem.

The bottom line is I got a client spawn multiple threads, calling my code,
one BulkRead, one BulkWrite, in both function, it has the
same identical loop as following:
   while (!userdata->ExitTransfer)
  {
      //I also added Lock here for the whole block here and
to serialize the call to
      //libusb_handle_events_timeout_completed, but it still does not work.
       struct timeval tv = { 1, 0 };
       int completed =0;

      err = libusb_handle_events_timeout_completed(NULL, &tv,&completed );
 }





Also from the trace, "what does  no URB with timeout or all handled by OS;
no timeout!" mean?

233.648362] [000024bc] libusbx: debug [libusb_get_next_timeout] no URB with
timeout or all handled by OS; no timeout!
[233.651362] [000024bc] libusbx: debug
[libusb_handle_events_timeout_completed] doing our own event handling
[233.651362] [000024bc] libusbx: debug [handle_events] poll() 2 fds with
timeout in 1000ms
[234.658463] [000024bc] libusbx: debug [handle_events] poll() returned 0
15BulkRead call  libusb_handle_events_timeout,completed value is 0; Error
Code is 0
[234.707468] [000024bc] libusbx: debug [libusb_get_next_timeout] no URB
with timeout or all handled by OS; no timeout!
[234.709468] [000024bc] libusbx: debug
[libusb_handle_events_timeout_completed] doing our own event handling
[234.710468] [000024bc] libusbx: debug [handle_events] poll() 2 fds with
timeout in 1000ms
[235.716569] [000024bc] libusbx: debug [handle_events]

Please advice.
thx

On Wed, Sep 12, 2012 at 2:14 PM, Tim Roberts <t...@probo.com> wrote:

> John Chen wrote:
> > Tim, I attache the usb debug trace and USB_Trace here. Yes, I did get
> > a timeout, but if you look at  USBTrace.txt, it have the following:
> >
> > [libusb_get_next_timeout] no URB with timeout or all handled by OS; no
> > timeout!
> > do you need what it means?
>
> It looks like you are running multiple simultaneous event loops.  Is
> that correct?  You don't need to do that.  You can see how the log
> output is garbled, apparently because the log output is intermixed with
> another thread writing at the exact same time.
>
> My best guess is that you have some kind of multithreading problem, but
> there's not much we can do without seeing the whole code, and I'm not
> sure you really want to do that.  You need to think about what order
> things are happening, remembering that asynchronous operations will
> always arrive at the most inconvenient time.
>
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> libusbx-devel mailing list
> libusbx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libusbx-devel
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to