libusbx apis(synchronous) multithreading issue

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

libusbx apis(synchronous) multithreading issue

hgs16
This post was updated on .
Hi all,

I am having issues when trying to use synchronous calls from multiple threads. (using libusbx-1.0.17-win)

From thread A I do libusb_bulk_transfer(dev_hnd,IN_EP,...) (read)  and in another thread B I do libusb_bulk_transfer(dev_hnd,OUT_EP,...) (write) to the same usb device using the same device handle.

What I am noticing is, send call is blocked until till read call is released (say by timeout).

Is this expected behaviour?

Kindly provide me with some insights to solve this issue.

Thanks


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Libusbx-devel] libusbx apis(synchronous) multithreading issue

Xiaofan Chen
On Sat, Feb 8, 2014 at 1:13 AM, hgs16 <[hidden email]> wrote:

> Hi all,
>
> I am having issues when trying to use synchronous calls from multiple
> threads.
>
> >From thread A I do libusb_bulk_transfer(dev_hnd,IN_EP,...) (read)  and in
> another thread B I do libusb_bulk_transfer(dev_hnd,OUT_EP,...) (write) to
> the same usb device using the same device handle.
>
> What I am noticing is, send call is blocked until till read call is released
> (say by timeout).
>
> Is this expected behaviour?

Yes. The synchronous APIs are blocking.

> Kindly provide me with some insights to solve this issue.

You can use asynchronous API.
http://libusb.sourceforge.net/api-1.0/io.html

--
Xiaofan

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusbx-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Libusbx-devel] libusbx apis(synchronous) multithreading issue

hgs16
Hi Xiaofan,

Thanks for your reply.

Does it mean synchronous libusb bulk transfers happening in different threads would block between them
even in when
1) IN and OUT endpoints of the USB device belong to different interfaces?
2) read & write to different usb devices?

Thanks

 

 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Libusbx-devel] libusbx apis(synchronous) multithreading issue

Toby Gray-2
In reply to this post by hgs16

On 7 February 2014 17:13, hgs16 <[hidden email]> wrote:
Hi all,

I am having issues when trying to use synchronous calls from multiple
threads.

>From thread A I do libusb_bulk_transfer(dev_hnd,IN_EP,...) (read)  and in
another thread B I do libusb_bulk_transfer(dev_hnd,OUT_EP,...) (write) to
the same usb device using the same device handle.

What I am noticing is, send call is blocked until till read call is released
(say by timeout).

Assuming I've understood what you are describing, this doesn't sound like correct behaviour.
 

Is this expected behaviour?

It shouldn't be. I'm fairly certain that I've used libusb in a similar way without a problem, for example I believe the barry project does exactly this.
 

Kindly provide me with some insights to solve this issue.

What operating system are you using and which libusb version? Is it possible to get the debug output from libusb for the situation you describe? This should be possible to get by setting the LIBUSB_DEBUG environment variable to 4.

Is there any possibility of sharing more information about the device you are trying to communicate with and the code that you're using libusb in?

Regards,

Toby

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusbx-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Libusbx-devel] libusbx apis(synchronous) multithreading issue

hgs16
Hi Toby,

Thanks for your response.

I am using libusbx-1.0.17-win on windows 7 machine. Also USB device is a custom STM32 device, making use of STM32 library adapted to behave as winusb device. So I have access to the USB device internals.

Configuration of the USB device.
Single configuration
      ->single interface 
          |-->end points IN
          |--> end points OUT

So is it the expected behaviour when libusb_bulk_transfer calls to different EPs from different threads, block each other(I use the same "device handle in the libusb_bulk_transfer call" ) 
(sorry to repeat myself, because I am not sure whether i explained properly)

If it is expected behaviour, how about configuring USB device to have two interfaces one for IN EP and the other for OUT EP? Will the blocking be happening even with this scenario?

I tried setting the debug log, but I could see not logs in the console. Not sure whats happening.

Kindly advice.

Thanks,

Hari



On Mon, Feb 10, 2014 at 5:08 AM, Toby Gray <[hidden email]> wrote:

On 7 February 2014 17:13, hgs16 <[hidden email]> wrote:
Hi all,

I am having issues when trying to use synchronous calls from multiple
threads.

>From thread A I do libusb_bulk_transfer(dev_hnd,IN_EP,...) (read)  and in
another thread B I do libusb_bulk_transfer(dev_hnd,OUT_EP,...) (write) to
the same usb device using the same device handle.

What I am noticing is, send call is blocked until till read call is released
(say by timeout).

Assuming I've understood what you are describing, this doesn't sound like correct behaviour.
 

Is this expected behaviour?

It shouldn't be. I'm fairly certain that I've used libusb in a similar way without a problem, for example I believe the barry project does exactly this.
 

Kindly provide me with some insights to solve this issue.

What operating system are you using and which libusb version? Is it possible to get the debug output from libusb for the situation you describe? This should be possible to get by setting the LIBUSB_DEBUG environment variable to 4.

Is there any possibility of sharing more information about the device you are trying to communicate with and the code that you're using libusb in?

Regards,

Toby

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusbx-devel



------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusbx-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Libusbx-devel] libusbx apis(synchronous) multithreading issue

Toby Gray-2
Hi Hari,

The logging output should be coming out on STDERR. Is your application a console application or does it have a windows GUI? If it has a windows GUI then you'll probably want to recompile libusb with USE_SYSTEM_LOGGING_FACILITY defined (see https://github.com/libusb/libusb/blob/master/msvc/config.h#L29). This will cause libusb to log the debug output as windows debug output. If you don't want to have to set environment variables then you can also compile with ENABLE_DEBUG_LOGGING enabled to force debugging output on by default.

Lastly you can enable logging from your code by calling libusb_set_debug(ctx, LIBUSB_LOG_LEVEL_DEBUG).

If you feel like digging into the libusb code to try to see what might be going wrong then area to look at is here: https://github.com/libusb/libusb/blob/master/libusb/sync.c#L44

Is it possible that your device firmware is refusing to accept data on the out endpoint until it has had all pending data from the in endpoint read?

Regards,

Toby


On 20 February 2014 14:50, Harikumar GS <[hidden email]> wrote:
Hi Toby,

Thanks for your response.

I am using libusbx-1.0.17-win on windows 7 machine. Also USB device is a custom STM32 device, making use of STM32 library adapted to behave as winusb device. So I have access to the USB device internals.

Configuration of the USB device.
Single configuration
      ->single interface 
          |-->end points IN
          |--> end points OUT

So is it the expected behaviour when libusb_bulk_transfer calls to different EPs from different threads, block each other(I use the same "device handle in the libusb_bulk_transfer call" ) 
(sorry to repeat myself, because I am not sure whether i explained properly)

If it is expected behaviour, how about configuring USB device to have two interfaces one for IN EP and the other for OUT EP? Will the blocking be happening even with this scenario?

I tried setting the debug log, but I could see not logs in the console. Not sure whats happening.

Kindly advice.

Thanks,

Hari



On Mon, Feb 10, 2014 at 5:08 AM, Toby Gray <[hidden email]> wrote:

On 7 February 2014 17:13, hgs16 <[hidden email]> wrote:
Hi all,

I am having issues when trying to use synchronous calls from multiple
threads.

>From thread A I do libusb_bulk_transfer(dev_hnd,IN_EP,...) (read)  and in
another thread B I do libusb_bulk_transfer(dev_hnd,OUT_EP,...) (write) to
the same usb device using the same device handle.

What I am noticing is, send call is blocked until till read call is released
(say by timeout).

Assuming I've understood what you are describing, this doesn't sound like correct behaviour.
 

Is this expected behaviour?

It shouldn't be. I'm fairly certain that I've used libusb in a similar way without a problem, for example I believe the barry project does exactly this.
 

Kindly provide me with some insights to solve this issue.

What operating system are you using and which libusb version? Is it possible to get the debug output from libusb for the situation you describe? This should be possible to get by setting the LIBUSB_DEBUG environment variable to 4.

Is there any possibility of sharing more information about the device you are trying to communicate with and the code that you're using libusb in?

Regards,

Toby

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusbx-devel




------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusbx-devel
Loading...