This is my first project using WinUsb driver and library.
My Host computer operates WINDOWS 10, all updates installed.
My High Speed device operates three data endpoints:
- OUT Command endpoint: the Host computer uses it to send command
- IN Reply endpoint: the Host computer receives reply to each command
- IN Stream endpoint: the device sends stream data, 1600 bytes with period 10 milliseconds.
In the Host application, there are two relevant threads:
- Command thread sends commands to Command pipe and receives replies from Reply pipe
- Stream thread collects data from Stream pipe
Non-waiting functions are used for all pipes.
Each thread works perfect if another thread is suspended.
However, if two threads work concurrently, the stream data appears corrupted in arbitrary points.
More analysis revealed the following facts:
- Corruption appears as a contiguous sequence of wrong bytes. The length of wrong sequence roughly corresponds to the length of commands and replies.
- Wrong sequence starts from arbitrary point not related to packet bounds.
- Wrong bytes may be different; sometimes, they are all zeroes, sometimes they looks as garbage.
- Time analysis suggests that the corruption occurs once the command is sent to Command pipe.
The effect disappears if I implement synchronization between the threads, so that read/write operations are separated in time. However, this is not acceptable solution, I want two threads to work asynchronously.
Has anybody faced such effect?