Android USB Accessory Multi Thread

前端 未结 2 729
醉梦人生
醉梦人生 2021-02-19 16:38

Headache caused by multi-threading and Android Open Accessory.

I need to communicate with a USB Accessory, but I need to do it from 2 threads.

2条回答
  •  遇见更好的自我
    2021-02-19 17:12

    As you want to do read and write in parallel, writing will always lead to a pause to read if the read is on the same part as write.

    May be you can follow similar approach as ConcurrentHashMap and use different locks for different segments and lock read only if write is on the same segment else allow the read to happen.

    This will

    1. Avoid blocking read during write in most scenarios
    2. Avoid collision and
    3. Definitely wont be a single thread approach.

    Hope that helps.

提交回复
热议问题