Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2021-01-06
18:37 • Closed ticket [570cb6afea]: Not getting expected outut. plus 5 other changes artifact: e0d3d2d8d5 user: sebres
17:04 • Open ticket [570cb6afea]. artifact: da187548cd user: arvind29
17:00 • Ticket [570cb6afea]: 5 changes artifact: 114b6ec49c user: arvind29
16:23 • Ticket [570cb6afea]: 5 changes artifact: 9319dae2ac user: sebres
16:07 • Closed ticket [570cb6afea]. artifact: da395d3e1a user: jan.nijtmans
15:18 • New ticket [570cb6afea]. artifact: 3726fbda7e user: arvind29

Not getting expected outut.

Closed / Works For Me570cb6afea12bc135f6c78afc0abae53a1918438Created 6 years agoUpdated 6 years ago
Descriptionplain2021-01-06 15:18:31
Below "vwait x " is not getting hang. Why ?

#tcl commands
set x {}
after 100 lappend x a
after 200 lappend x b
after 300 lappend x c
after 700
vwait x
set x
jan.nijtmanswiki2021-01-06 16:07:28

The "after" commands are only executed when an event loop is running. In your case, the "vwait" runs the event loop, so that's when the lappends happen.

If you put an "update" just before the vwait, it hangs as expected:

#tcl commands set x {} after 100 lappend x a after 200 lappend x b after 300 lappend x c after 700 update vwait x set x

sebreswiki2021-01-06 16:23:16

after 700 is a simple sleep (no events executed during this sleep process at all); if you want that 3 timer events (100, 200 and 300ms) going executed during this sleep, you have to implement it:

  • either using other vwait:
      - after 700
      + after 700 {set ::to 1}; vwait ::to
    
  • By the way there is also an enhancement RFE [fdfbd5e10] introducing timeout by vwait, e. g. vwait 700 _ for exactly such purposes.
  • or using some cycle from now up to now+700ms, with update (and small after to avoid busy wait) inside the cycle

arvind29plain2021-01-06 17:00:13
My query is...
I have configured the TCL with -enable_thread flag and run below TCL commands.
should it be hang or not ?


#tcl commands
set x {}
after 100 lappend x a
after 200 lappend x b
after 300 lappend x c
after 700
vwait x
set x
arvind29 Open ticket [570cb6afea]. [History diff]2021-01-06 17:04:06
sebreswiki2021-01-06 18:37:53

> I have configured the TCL with -enable_thread flag and run below TCL commands.

option "-enable_thread" (as well as threads themselves) has nothing to do with an event cycle (you handle quasi single-threaded here), this option just allows to use threads in tcl at all (e. g. thread module or some system threads, so the library is usable with threads).

Also don't confuse tcl with other langs using GIL (for example with python), every tcl interpreter belong to exactly one main thread, whom is allowed to execute code in this interpreter. There are few exceptions in tcl world, which could act across the threads or are shared between the workers.

Event cycle is to consider single-threaded (basically this is true in every language).

> should it be hang or not ?

yes, this is fully expected behavior, because as already said after 700 does just a sleep for current thread, the events are not executed at all; read documentation or wiki :: Tcl event loop for more info.

Regarding the threads, you may take a look at thread package.

Log in (anonymous is fine) to add a comment.