TCL: Two way communication between threads in Windows

后端 未结 1 1339
别那么骄傲
别那么骄傲 2021-01-14 04:19

I need to have two way communication between threads in Tcl and all I can get is one way with parameters passing in as my only master->helper communication channel. Here is

相关标签:
1条回答
  • 2021-01-14 04:48

    Here is a small example that shows how two processes can communicate. First off the child process (save this as child.tcl):

    gets stdin line
    puts [string toupper $line]
    

    and then the parent process that starts the child and comunicates with it:

    set fd [open "| tclsh child.tcl" r+]
    
    puts $fd "This is a test"
    flush $fd
    
    gets $fd line
    puts $line
    

    The parent uses the value returned by open to send and receive data to/from the child process; the r+ parameter to open opens the pipeline for both read and write.

    The flush is required because of the buffering on the pipeline; it is possible to change this to line buffering using the fconfigure command.

    Just one other point; looking at your code you aren't using threads here you are starting a child process. Tcl has a threading extension which does allow proper interthread communications.

    0 讨论(0)
提交回复
热议问题