Re: Own implementation of multithread



More portable would be to create your threads with
Tcl_CreateThread

As I don't see you using anyting other than default attributes for the pthread_create.


Beyond that I agree with Alexandre andwonder if instead you can make the main controlling flow of control Tcl, and just supply appropriate
compiled extensions where needed, using the Tcl Thread package.

There are a few useful pages on the wiki (wiki.tcl.tk) if you search for threads. Including http://wiki.tcl.tk/1339 which has a 'cookbook' for using threads at the Tcl level. There are also some gotchas given in some of those pages and a nice page on threads vs. events that _may_ make you reconsider the architecture of your application.

Ron.

lkfstephen@xxxxxxxxx wrote:
Dear all,

I am working on a multithread application.
I have already built the TCL using --enable-threads.

In c++ code, I am trying to create many threads, each thread will
create its own interpreter.
Each interpreter will need to eval a script.

For example,

void * func( void * null ){
Tcl_Interp* tcl_interp = Tcl_CreateInterp();
Tcl_Init(tcl_interp);
char * script = "set a 1\n"
"set b 2\n"
"puts $a\n"
"puts $b\n";
Tcl_EvalObjEx(tcl_interp, script , TCL_EVAL_GLOBAL);
delete tcl_interp;
}

int main (){
...
for (int i = 0; i < 10000; ++i)
pthread_create(&tid,NULL,func,NULL);
...
}

I would like to ask is this approach is wrong?

Stephen Lai


--
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321
.



Relevant Pages

  • Tcl thread local storage memory problem
    ... I am working on an application that originally uses one thread, TCL ... and the C-library to initialize an interpreter and executing standard ... InitializeThreadLocalStorage(); /*If no threads, initialize ... able to get Tcl thread local storage ...
    (comp.lang.tcl)
  • Re: File data format
    ... This is how I always look at data processing with Tcl: ... then let the very effecient tcl interpreter do the parsing. ... Create procs that match the data keys. ... date, commit, and compile, that matched the same signature, then your ...
    (comp.lang.tcl)
  • Re: No argv, argc for worker thread
    ... I expected that a Tcl interpreter started in any manner would accept options ... This is how the interpreter works with command line options ... a "main" script processes command line ...
    (comp.lang.tcl)
  • Re: Tcl/TK is indeed dying
    ... A fat Tcl interpreter has impact to all wanting to see Tcl linked to ... other software and embedded in hardware, because fatness make it less ...
    (comp.lang.tcl)
  • Re: looking for tcl based Cisco like command line interface
    ... TinyTcl and Jim would be fine to save resources, but first is missing some newer tcl sub-/commands and later has no exec-command at all. ... Only want to install one single tcl/etcl/tclkit interpreter and a single tcl script. ... Funny, the cli can be run from any computer remote,using snmp get/get-next/set for communication to the network device, therefore got a remote console program too. ... extreme environments) based on ARM or Coldfire processor using Debian Linux/ucLinux should be extended with a CLI that is similar in behaviour, handling and naming conventions to the well known cisco command line interface (several user-visible application-specific commands, along with a help, different management operation levels like "enable", "config", line driven only, tab expansion, no special graphics or ascii terminal commands) ...
    (comp.lang.tcl)