Tcl在Unix/Linux环境下多线程支持环境搭建

来源:互联网 发布:apache 开启虚拟主机 编辑:程序博客网 时间:2024/05/18 13:25

一、 下载源码

    tcl8.5        http://tcl.tk/software/tcltk/8.5.html

    tclThread2.6 http://core.tcl.tk/thread/info/2e574064a4

二、安装tcl8.5

   

tar -xvf tcl8.5.9-src.tar.gzcd tcl8.5.9cd unix./configure --prefix=$HOME/tools/tcl8.5.9 --enable-threadsmake ; make install

注:要支持tcl多线程必须加编译选项 --enable-threads

 

三、 安装tclThread2.6

unzip tclthread2.6.zipcd tclthread2.6configure --with-tcl=$HOME/sft/tcl8.5.9/unix --prefix=$HOME/tools/tcl8.5.9/lib/tcl8.5make ; make install

注:编译tclthread2.6时需要配置文件tclconfig,这个配置文件可以从其他安装包中获取 如mysqltcl-3.05/tclconfig。

其实目录tclconfig下有一个安装脚本名为:install-sh,内容如下:

#!/bin/sh## install - install a program, script, or datafile# This comes from X11R5; it is not part of GNU.## $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $## This script is compatible with the BSD install script, but was written# from scratch.## set DOITPROG to echo to test this script# Don't use :- since 4.3BSD and earlier shells don't like it.doit="${DOITPROG-}"# put in absolute paths if you don't have them in your path; or use env. vars.mvprog="${MVPROG-mv}"cpprog="${CPPROG-cp}"chmodprog="${CHMODPROG-chmod}"chownprog="${CHOWNPROG-chown}"chgrpprog="${CHGRPPROG-chgrp}"stripprog="${STRIPPROG-strip}"rmprog="${RMPROG-rm}"instcmd="$mvprog"chmodcmd=""chowncmd=""chgrpcmd=""stripcmd=""rmcmd="$rmprog -f"mvcmd="$mvprog"src=""dst=""while [ x"$1" != x ]; do    case $1 in-c) instcmd="$cpprog"    shift    continue;;-m) chmodcmd="$chmodprog $2"    shift    shift    continue;;-o) chowncmd="$chownprog $2"    shift    shift    continue;;-g) chgrpcmd="$chgrpprog $2"    shift    shift    continue;;-s) stripcmd="$stripprog"    shift    continue;;*)  if [ x"$src" = x ]    thensrc=$1    elsedst=$1    fi    shift    continue;;    esacdoneif [ x"$src" = x ]thenecho "install:  no input file specified"exit 1fiif [ x"$dst" = x ]thenecho "install:  no destination specified"exit 1fi# If destination is a directory, append the input filename; if your system# does not like double slashes in filenames, you may need to add some logicif [ -d $dst ]thendst="$dst"/`basename $src`fi# Make a temp file name in the proper directory.dstdir=`dirname $dst`dsttmp=$dstdir/#inst.$$## Move or copy the file name to the temp name$doit $instcmd $src $dsttmp# and set any options; do chmod last to preserve setuid bitsif [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fiif [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fiif [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fiif [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi# Now rename the file to the real destination.$doit $rmcmd $dst$doit $mvcmd $dsttmp $dstexit 0


 

四、测试脚本验证tcl的多线程。

package require Threadputs "*** I'm thread [thread::id]"# Create 3 threadsfor {set thread 1} {$thread <= 3} {incr thread} {set id [thread::create {# Print a hello message 3 times, waiting# a random amount of time between messagesfor {set i 1} {$i <= 3} {incr i} {after [expr { int(500*rand()) }]puts "Thread [thread::id] says hello"}}] ;# thread::createputs "*** Started thread $id"} ;# forputs "*** Existing threads: [thread::names]"# Wait until all other threads are finishedwhile {[llength [thread::names]] > 1} {after 500}puts "*** That's all, folks!"


 

运行结果:

*** I'm thread tid000005EC*** Started thread tid000016E8*** Started thread tid00000100*** Started thread tid00001260*** Existing threads: tid00001260 tid00000100 tid000016E8 tid000005ECThread tid00000100 says helloThread tid000016E8 says helloThread tid00001260 says helloThread tid00000100 says helloThread tid00000100 says helloThread tid000016E8 says helloThread tid00001260 says helloThread tid00001260 says helloThread tid000016E8 says hello*** That's all, folks!

 

原创粉丝点击