>From inside NaviServer, I'd like to repeatedly write data to some files in the background, while letting the thread that schedules the writes go on to do other work. The obvious way to do that might seem be simply calling Tcl's "open" on each file and then doing:
fconfigure $fd -blocking 0 However, the Tcl docs clearly say that: http://www.tcl.tk/man/tcl8.6/TclCmd/puts.htm The application must use the Tcl event loop for nonblocking output to work; otherwise Tcl never finds out that the file or device is ready for more output data. I believe most threads in NaviServer never enter the Tcl event loop, and therefore Tcl nonblocking IO won't work at all. Is that correct? Is there another simple approach I should use from NaviServer instead, perhaps something analogous to the "background delivery" (ns_writer) scheme for writing to network sockets? Or would I need to roll my own? For rolling my own, what approach and APIs would make the most sense to use? So far I'm guessing something like this: 1. Temporarily store the data to be written in an nsv somewhere, and have a special write-to-file thread running in the background, which reads from the nsv. 2. The write-to-file thread can itself use Tcl noblocking IO to do the actual writes, and enter the Tcl event loop whenever it's idle. 3. Send a signal to the write-to-file thread telling it, "Wake up, you have work to do." But how should I do step 3 above? Normally I'd use ns_cond (ns_event), but that can't work if my write-to-file thread is waiting in the Tcl event loop, instead of waiting on a conditional variable, right? So what's the right way to send a signal to a thread that's using the Tcl event loop? Should I be using "thread::send" for that? Or is there some other or better approach? (I don't currently have the Tcl Threads Extension built for my NaviServer.) Hm, if I need to use thread::send anyway, maybe I can (should?) simply include all the data in each message, and skip queuing it temporarily in an nsv? https://www.tcl.tk/man/tcl8.6/ThreadCmd/thread.htm#M17 Thanks in advance for your advice! -- Andrew Piskorski <a...@piskorski.com> _______________________________________________ naviserver-devel mailing list naviserver-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/naviserver-devel