multithreading - Linux, cancel blocking read() -


in multi-threaded linux program used serial communication, possible (and best approach) terminate blocking read() call thread?

i keep reactive possible , avoid use of timeouts repeated polling.

the background of question i'm trying create scala serial communication library linux using jni. i'm trying keep native side simple possible providing, amongst others, read() , close() function. on scala side, 1 thread call read() , block until data serial port available. however, serial port can closed other means, resulting in call close(). now, free blocked thread, somehow need cancel system read call.

one popular trick: instead of blocking in read(), block in select() on both serial-socket , pipe. when thread wants wake thread, can writing byte other end of pipe. byte cause select() return , thread can cleanup , exit or whatever needs do. (note make work 100% reliably you'll want set serial-socket non-blocking, ensure thread blocks in select() , never in read())


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -