Wednesday, 15 August 2012

multithreading - Set TCL vwait variable from a thread -



multithreading - Set TCL vwait variable from a thread -

i need able set variable end vwait within thread. because have loop locks interperator , hence gui running until completes.

i'm wanting function sleep command this:

global endsleep after ${sleeptime_ms} set endsleep 1 vwait endsleep

only need set vwait variable when while loop querying device exits.

here code currently:

proc ::visa::wait {visaalias} { # link global variable global endwait # execute commands in thread gui not locked while executing set thread [thread::create] thread::send ${thread} [list set visaalias ${visaalias}] thread::send ${thread} { source molexvisa.tcl # temporarily create new connection device visa::connect ${visaalias} # query operation finish bit visa::query ${visaalias} "*opc?" # go on effort read opc bit until response given; typically 1 while {[string equal [visa::read ${visaalias}] ""]} {} # destroy temporary connection visa::disconnect ${visaalias} # set vwait variable set endwait 1 } # wait thread end vwait endwait # mark thread termination thread::release ${thread} }

currently thread still freezing gui. also, since variable in thread , variable i'm expecting aren't same, waits forever.

any advice or help appreciated. believe i've exhausted other more practical ways of accomplishing task, more insight welcomed.

use -async flag thread::send. default, ::thread::send blocks until script has been executed (which defeats of time utilize of threads).

if utilize -async flag, can utilize optional variable argument thread::send , vwait that, e.g.

set tid [thread::create { proc fib n { if {$n == 0 || $n == 1} {return 1} homecoming [expr {[fib [expr {$n - 1}]] + [fib [expr {$n - 2}]]}] } thread::wait }] ::thread::send -async $tid [list fib $num] result vwait result ::thread::release $tid # ... result

this should prevent gui freezing. note implementation of fibonacci not best , placeholder "some expensive calculation".

multithreading tcl visa

No comments:

Post a Comment