Last active
July 6, 2022 12:51
-
-
Save gahr/5ef70bf9102fc83a4b4c133e940c91da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set post_args [list -detached] | |
if {[lindex $::argv 0] eq {nowait}} { | |
lappend post_args -nowait | |
} | |
package require Thread | |
set num_threads 4 | |
tsv::set v num_done 0 | |
set tp [tpool::create -minworkers 1 -maxworkers 10] | |
for {set i 0} {$i < $num_threads} {incr i} { | |
tpool::post {*}$post_args $tp { | |
after 1000 | |
puts "[thread::id] - [clock format [clock seconds]]" | |
tsv::incr v num_done | |
} | |
} | |
while {[tsv::get v num_done] != $num_threads} { | |
after 1000 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% tclsh8.7 test.tcl | |
tid0x800c14300 Wed Jul 06 12:50:18 UTC 2022 | |
tid0x800c13c00 Wed Jul 06 12:50:18 UTC 2022 | |
tid0x800c13500 Wed Jul 06 12:50:18 UTC 2022 | |
tid0x800c12e00 Wed Jul 06 12:50:18 UTC 2022 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% tclsh8.7 test.tcl nowait | |
tid0x800c12e00 Wed Jul 06 12:50:34 UTC 2022 | |
tid0x800c12e00 Wed Jul 06 12:50:35 UTC 2022 | |
tid0x800c12e00 Wed Jul 06 12:50:36 UTC 2022 | |
tid0x800c12e00 Wed Jul 06 12:50:37 UTC 2022 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment