Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how can tcl program be written to take advantage fo 8 cpu machine? ipc? message passing? or?

83 views
Skip to first unread message

gavino

unread,
Feb 24, 2012, 7:51:42 PM2/24/12
to
curious how tclers write programs that are not stuck on 1 cpu

GN

unread,
Feb 25, 2012, 6:51:59 AM2/25/12
to
On Feb 25, 1:51 am, gavino <gavcom...@gmail.com> wrote:
> curious how tclers write programs that are not stuck on 1 cpu

libthread, aolserver/naviserver

George Petasis

unread,
Feb 25, 2012, 7:35:54 AM2/25/12
to
Στις 25/2/2012 02:51, ο/η gavino έγραψε:
> curious how tclers write programs that are not stuck on 1 cpu

I use the threads package for this (creates interpreters on different
threads), but I wish this kind of usage was easier in Tcl...

George

Tcl Bliss

unread,
Feb 25, 2012, 3:53:44 PM2/25/12
to
Multi-threaded programming in Tcl is super simple. But, what happens
often is that people get confused and scared away by the language used
to explain multi-threaded programming, like using mutexes and
condition variables.

Let me make it clear -- you do not need to know anything about mutexes
or condition variables etc. Those can be used for advanced
programming, if you ever need them and once you learned the basics.
Otherwise, basics are perfectly fine and enough for everyday use.

Example:

package require Thread;

thread::create { #your code goes here}
# anything you want to do, the thread exits/closes once your code
completes}

or

set mythread [thread::create];
# this is a long lived thread, you can keep sending your code there,
do [thread::release $mythread] to close/exit it.

set output [thread::send $mythread {#your code}]

or

thread::send -async $mythread {#your code} output; vwait output;


Although multi-threaded programming is very simple to start with, you
only need it in cases where your application reaches 100% CPU usage or
you have some code that could block your application from responding
for long periods of time, otherwise you just waste memory and reduce
performance by needlessly creating and using threads.

Andreas Kupries

unread,
Mar 1, 2012, 3:43:51 AM3/1/12
to
Tcl Bliss <tcl....@gmail.com> writes:

> Multi-threaded programming in Tcl is super simple. But, what happens

Note also

http://code.google.com/p/tcl-hwloc/

a Tcl binding to Portable Hardware Locality (hwloc). That allows a Tcl
script to query the system for number of processors, cores, and
whatnot. Information needed if an application wishes to dynamically
configure itself to take advantage of (all) the resources it has
available.

--
So long,
Andreas Kupries <akup...@shaw.ca>
<http://www.purl.org/NET/akupries/>
Developer @ <http://www.activestate.com/>
18'th Annual Tcl/Tk Conference: 2011, Manassas, VA USA
http://www.tcl.tk/community/tcl2011/
-------------------------------------------------------------------------------

Gerald W. Lester

unread,
Mar 1, 2012, 9:43:00 AM3/1/12
to
On 2/25/12 2:53 PM, Tcl Bliss wrote:
> Multi-threaded programming in Tcl is super simple. ...
> Although multi-threaded programming is very simple to start with, you
> only need it in cases where your application reaches 100% CPU usage or
> you have some code that could block your application from responding
> for long periods of time, otherwise you just waste memory and reduce
> performance by needlessly creating and using threads.

And where "you have some code that could block your application from
responding for long periods of time" is normally true in other languages,
like waiting on data to appear at a socket -- Tcl steps in with the event loop.


--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+

quiet_lad

unread,
Mar 8, 2012, 3:33:36 AM3/8/12
to
On Mar 1, 12:43 am, Andreas Kupries <akupr...@shaw.ca> wrote:
> Tcl Bliss <tcl.bl...@gmail.com> writes:
> > Multi-threaded programming in Tcl is super simple. But, what happens
>
> Note also
>
>        http://code.google.com/p/tcl-hwloc/
>
> a Tcl binding to Portable Hardware Locality (hwloc). That allows a Tcl
> script to query the system for number of processors, cores, and
> whatnot. Information needed if an application wishes to dynamically
> configure itself to take advantage of (all) the resources it has
> available.
>
> --
> So long,
>         Andreas Kupries <akupr...@shaw.ca>
>                         <http://www.purl.org/NET/akupries/>
>         Developer @     <http://www.activestate.com/>
>         18'th Annual Tcl/Tk Conference:  2011, Manassas, VA USA
>        http://www.tcl.tk/community/tcl2011/
> -------------------------------------------------------------------------------

very cool thx

quiet_lad

unread,
Mar 8, 2012, 3:32:50 AM3/8/12
to
Very cool, and thank you for the reassurance, esp since I don't know
c.
Where are some sources aside from man pages to learn more?

Tcl Bliss

unread,
Mar 8, 2012, 11:23:50 PM3/8/12
to

quiet_lad

unread,
Mar 8, 2012, 11:33:56 PM3/8/12
to
ah cool! thx!

quiet_lad

unread,
Mar 8, 2012, 11:43:28 PM3/8/12
to
Can tcl spawn an interpreter for each web request? and then that
interp call db or tdom or template program to build page from data? I
read that paul graham did this in lisp with viaweb. The threads are
not needed then, since each interp is a process that then requests
more input from browser. I read about some of this with continuity
the perl library. Does this kind of operation make programming web
apps simpler?

quiet_lad

unread,
Mar 8, 2012, 11:44:20 PM3/8/12
to
On Mar 1, 6:43 am, "Gerald W. Lester" <Gerald.Les...@KnG-
Consulting.net> wrote:
> On 2/25/12 2:53 PM, Tcl Bliss wrote:
>
> > Multi-threaded programming in Tcl is super simple. ...
> > Although multi-threaded programming is very simple to start with, you
> > only need it in cases where your application reaches 100% CPU usage or
> > you have some code that could block your application from responding
> > for long periods of time, otherwise you just waste memory and reduce
> > performance by needlessly creating and using threads.
>
> And where "you have some code that could block your application from
> responding for long periods of time" is normally true in other languages,
> like waiting on data to appear at a socket -- Tcl steps in with the event loop.
>
> --
> +------------------------------------------------------------------------+
> | Gerald W. Lester, President, KNG Consulting LLC                        |
> | Email: Gerald.Les...@kng-consulting.net                                |
> +------------------------------------------------------------------------+

so most tcl apps can work without threads but stay on 1 cpu. What
happens when work overocmes 1 cpu? Can you fork another interpreter
to handle more load?
0 new messages