Le 11/11/12 10:03 AM, Julien Vermillard a écrit :
> when the I/O selector code :
>  - queue.isEmpty() ?
>  - set write flag off
>
> write thread code :
>  - queue.add(message)
>  - set write flag on

There are 6 possible cases :
1) QIE, SWFOFF, QA, SWFON : OK
2) QIE, QA, SWFOFF, SWFON : OK
3) QIE, QA, SWFON, SWFOFF : problem
4) QA, QIE, SWFOFF, SWFON : OK
5) QA, QIE, SWFON, SFWOFF : can't happen
6) QA, SWFON, QIE, SWFOFF : can't happen

The only problematic case is (3).
If we want to fix that, we sure need some kind of synchronization
between the two threads. What if we have an atomic boolean flag shared
between the two threads, that said the write thread has switch the write
flag to true (the write thread is the only one to set it to true, the
selector thread just switch it to false) ?

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 

Reply via email to