您的位置:首页 > 其它

non-blocking and blocking mode

2010-07-26 15:40 417 查看
non-blocking mode指的是不须等待相关的channel,而可以执行其他进程。但blocking mode则是遇到channal无空时,必须停下来等待。

http://www.beedub.com/book/2nd/event.doc.html

By default, I/O channels are blocking. A gets or read will wait until data is available before returning. A puts may also wait if the I/O channel is not ready to accept data. This behavior is OK if you are using disk files, which are essentially always ready. If you use pipelines or network sockets, however, the blocking behavior can hang up your application.

The fconfigure command can set a channel into non-blocking mode. A gets or read command may return immediately with no data. This occurs when there is no data available on a socket or pipeline. A puts to a non-blocking channel will accept all the data and buffer it internally. When the underlying device (i.e., a pipeline or socket) is ready, then Tcl automatically writes out the buffered data. Non-blocking channels are useful so your application can do something else while waiting for the I/O channel. You can also manage several non-blocking I/O channels at once. Non-blocking channels should be used with the fileevent command described earlier. The following command puts a channel into non-blocking mode:

fconfigure fileID -blocking 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: