Trying to make a function like InetTelnetRunScript callable by multiple threads simultaneously has the following issues:
1) It should lock on a per-telnet-handle basis - if not you will end up sending junk to the telnet server.
2) If you lock it on a per-telnet handle basis, then really you should call it from the other thread with a different telnet handle for the "threading" to be useful. If not, you are still going to get the behavior you see now.
3) In my view, using InetTelnetRunScript in this situation (you want the telnet server to execute multiple commands in parallel) may not be appropriate. Instead, I would think that each thread should call InetTelnetWrite and InetTelnetRead (NOT InetTelnetReadUntil) with thread-specific telnet handles to get parallel behavior. Also, the InetTelnetRead should read in very small chunks to prevent one thread from waiting on TCP data for too long and blocking out the other threads (same reason not to use ReadUntil). Note that this should result in parallel behavior because even though there is a library lock, the various threads should be able to grab that lock alternately and maintain multiple telnet sessions.
4) If you want to write your own implementation then you may have to use something more low-level than the CVI TCP library because that library also locks on a library level and so you will pretty much have to do 3 using TCP handles instead of Telnet handles - I cannot see any additional benefit in doing this.
5) If you write your own implementation using something like Windows sockets, then the only benefit you get over 3 (and 4) is that you can read in larger chunks. But this is not always feasible because anyway you need to examine every byte for control codes, etc because of the nature of the telnet protocol. You may be able to estimate the number of bytes to read for some commands and then read in larger chunks there and save some time - but I am not sure if this is worth doing or even that it can be cleanly implemented.
So, I would recommend 3.
Best regards,
Mohan