f



enable-threads with multi-threaded/multi-interp app but w/o tcl thread api? #2

Ive been searching for an answer to a basic question and have been
unable to find it :

If I have a multi-threaded C++ application with embedded tcl, using
pthreads and each thread having its own tcl interpreter, do I need to
build the tcl library with threads enabled?  I am not using the TCL
thread API, I am simply creating and using multiple tcl interpreters
within separate pthreads(again, each thread having its own interp).
0
6/26/2011 3:39:30 PM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

3 Replies
1039 Views

Similar Articles

[PageSpeed] 34

Hello JV,

Am 26.06.11 17:39, schrieb JV:
> If I have a multi-threaded C++ application with embedded tcl, using
> pthreads and each thread having its own tcl interpreter, do I need to
> build the tcl library with threads enabled?  I am not using the TCL
> thread API, I am simply creating and using multiple tcl interpreters
> within separate pthreads(again, each thread having its own interp).

I don't know the answer, but why do you want to avoid the threaded 
build? Do you fear its getting slower due to additional locks? An 
advantage of using Tcl instead of pthreads directly (i.e., 
Tcl_CreateThread() and friends), you gain the advantage of platform 
independence, which means mainly Windows. Tcls thread API in the C level 
mostly corresponds to pthreads. Of course, to use these functions, you 
must have a threaded build. IIRC there was only one reason to avoid the 
threaded build on Unix, namely fork()

	Christian

0
auriocus1 (391)
6/26/2011 4:24:18 PM
Thank you for the response.  This is for an existing application that uses 
pthreads extensively.  It will only be implemented on Linux, but we are 
switching from Suse to Red Hat distribution and are rebuilding Tcl.  The 
reason to not use the threaded build is because it is not the default distro 
build and there is fear of breaking other applications.  Is the Tcl thread 
api wrapping pthreads calls?  It is unclear to me whether the enable-threads 
option is needed ONLY when using the tcl threads api.

Jon


"Christian Gollwitzer" <auriocus@gmx.de> wrote in message 
news:iu7mfj$u71$1@dont-email.me...
> Hello JV,
>
> Am 26.06.11 17:39, schrieb JV:
>> If I have a multi-threaded C++ application with embedded tcl, using
>> pthreads and each thread having its own tcl interpreter, do I need to
>> build the tcl library with threads enabled?  I am not using the TCL
>> thread API, I am simply creating and using multiple tcl interpreters
>> within separate pthreads(again, each thread having its own interp).
>
> I don't know the answer, but why do you want to avoid the threaded build? 
> Do you fear its getting slower due to additional locks? An advantage of 
> using Tcl instead of pthreads directly (i.e., Tcl_CreateThread() and 
> friends), you gain the advantage of platform independence, which means 
> mainly Windows. Tcls thread API in the C level mostly corresponds to 
> pthreads. Of course, to use these functions, you must have a threaded 
> build. IIRC there was only one reason to avoid the threaded build on Unix, 
> namely fork()
>
> Christian
>
> 


0
6/28/2011 1:41:44 AM
Am 28.06.11 03:41, schrieb JV:
> Thank you for the response.  This is for an existing application that uses
> pthreads extensively.  It will only be implemented on Linux, but we are
> switching from Suse to Red Hat distribution and are rebuilding Tcl.  The
> reason to not use the threaded build is because it is not the default distro
> build and there is fear of breaking other applications.

> Is the Tcl thread
> api wrapping pthreads calls?  It is unclear to me whether the enable-threads
> option is needed ONLY when using the tcl threads api.

The threaded build has three differences to the non-threaded:

1) It defines the C API for threads
http://www.tcl.tk/man/tcl/TclLib/Thread.htm
In an unthreaded build, these functions are no-ops. In a threaded build, 
they are wrappers around pthreads (or windows threads in Win). Beware 
that when you compile an extension, USE_THREADS must also be defined, 
otherwise you get the no-op functions...

2) It introduces mutexes and locks into the Tcl core to make it thread 
safe.

3) It is possible to load the "Thread" package, which gives script level 
access to creating threads and inter-thread communication (posting 
events, shared variables)

That said, it seems very likely to me that you would need a threaded 
core even if you create the threads using pthreads directly, 
circumventing the C thread API - except if you have only one interp. 
Note that it is not allowed to load Tk in more than one thread, AFAIK 
that is true for any GUI toolkit.

There were some discussions on this group why the unix build is 
non-threaded by default (as opposed to windows), and the reason had 
something to do with fork(). Try googling for that thread (no pun intended;)

	Christian
0
auriocus1 (391)
6/28/2011 6:32:50 AM
Reply:

Similar Artilces:

enable-threads with multi-threaded/multi-interp app but w/o tcl thread api?
Ive been searching for an answer to a basic question and have been unable to find it : If I have a multi-threaded C++ application with embedded tcl, using pthreads and each thread having its own tcl interpreter, do I need to build the tcl library with threads enabled? I am not using the TCL thread API, I am simply creating and using multiple tcl interpreters within separate pthreads(again, each thread having its own interp). From the Wiki ( http://wiki.tcl.tk/1339 ) Some consolidated rules for embedding Tcl in a threaded application: * You can NEVER use the same interpreter from more than one thread * If you only have one Tcl Interpreter: * You can use either Unthreaded or Threaded Tcl * No "Big Global Mutex" is required for Unthreaded Tcl Build (Never required for Threaded Tcl build) * If you have Multiple Tcl Interpreters: * If you are using an Unthreaded Tcl a "Big Global Mutex" is required for ALL calls to functions in libtcl * If you are using a Threaded Tcl, no mutex locks are required You are responsible for the "big global mutex" if you have multiple Tcl interpreters "owned" by multiple threads and unthreaded Tcl. Thanks, Roy Keene ...

[TCL] multi-threaded tcl apps
Hi, Where can one find complete documentation on the ttrace package to the Thread package? I'd like to know what commands are available in ttrace and how to use them. --------------------------------------------- Andrew R. Falanga (a non-HP employee) Hewlett-Packard Company 11311 Chinden Blvd. Boise, Idaho --------------------------------------------- Please note: The e-mail address is purposely mangled. I do not wish my account at HP to become a spam haven. If you wish to e-mail me, the address consists of a dot between my first and last names (excluding my middle initial). The rest...

Change Multi threaded DLL to Multi threaded
Hi, If I redistribute an app which is built with the "Multi threaded DLL" option (windows), can I be sure that the user has all the necessary run-time DLL files on his/her computer? I want to build the calendar sample as a Multi threaded instead of Multi threaded DLL, to get rid of run-time dll depencies. When I change the code generation setting in MS Visual C++ 2008 Express Ddition to Multi threaded, I get lots of link errors, for example: Error 1 error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj) MSVCRTD.lib Error 2 error LNK2005...

Multi-Threading in Tcl #2
Hai, Can anyone provide me with a good Multi-threading programming in Tcl with explaination Regards, RR On 24 sep, 11:16, RR <meetra...@gmail.com> wrote: > Hai, > > Can anyone provide me with a good Multi-threading programming in Tcl > with explaination > > Regards, > RR You will want to look at the threads extension. http://wiki.tcl.tk/2770 provides a lot of details and references. If you are interested in concurrency as a general subject, then tuple spaces (http://wiki.tcl.tk/3946) may be useful too. Regards, Arjen On Mon, 24 Sep 2007 04:46:27 -0700, Arje...

Will combining a single threaded app with multi-thread library cause problem? #2
I have a single threaded application linking with all single threaded libraries. Now, I try to link a multi-threaded library and compile the single threaded application with multi-thread flag (-mt) in Solaris. However, the application receives SIGBUS indicating "Invalid address alignment" and crashes. Will mixing the single and multiple thread cause this problem? Thanks in advance. Sagenaut sagenaut@gmail.com wrote: Once is enough! -- Ian Collins "Ian Collins" <ian-news@hotmail.com> wrote in message news:6mn7jrFgdr8lU24@mid.individual.net... > sagenaut@gmail.com wrote: > > Once is enough! Well, I have fuck%ed up real bad and sent multiple copies of the _exact_ same message. Humm.... Once is enough indeed, but perhaps shed a little compassion... I could swear one time my news service sent multiple copies! Excuses, excuses...! :^( Chris M. Thomasson wrote: > "Ian Collins" <ian-news@hotmail.com> wrote in message > news:6mn7jrFgdr8lU24@mid.individual.net... >> sagenaut@gmail.com wrote: >> >> Once is enough! > > Once is enough indeed, but perhaps shed a little > compassion... Maybe, the poor soul was posing through google and we all know what a chore that can be. -- Ian Collins ...

multi-threading in tcl
I know this has been asked before, but I thought I'd ask again since it's been awhile. Is multi-threading supported in tcl? I know there's a compile switch, but does it work well? Well I know the latest release by ActiveState has threading enabled by default. There is quite a bit of info on threading on the wiki: http://wiki.tcl.tk/ I would just put "thread" in the search term and away you go, threading information heaven. HTH Robert ...

threading a thread
I have a program written in Python that checks a class B network (65536 hosts) for web servers. It does a simple TCP socket connect to port 80 and times out after a certain periods of time. The program is threaded and can do all of the hosts in about 15 minutes or so. I'd like to make it so that I can check for other open ports (instead of just port 80) and I'd like to thread the port checks as well. Right now I'm just prototyping and the threaded hosts portion works very well for my needs. I'd just like to add a threaded ports check and wanted to know if anyone had don...

To thread or not to thread
My app needs to check a number of things on the web. This can be done in the background. I use idHTTP to pull data in. This process is broken down into small parts and the subroutinen are called in the OnIdle handler of the main form. I notice that sometimes idHTTP needs a considerable time to build the connection/fetch the data and the application doesn't repond to user actions during such periods. To cope with this I have now implemented the web data fetching in a thread with priority tpIdle. I think the problem of non-response has gone, ut it is difficult to test. Am...

To thread or not to thread ?
The threads of discussion about threads have been enlightening in exposing some of the low level issues which could possibly affect MT code and, more importantly, served also to bring awareness to the unsuspecting (me for one). It leaves me wondering if writing MT code is even to be pursued at this point in time, or at least "where's the guidebook to read is that will facilitate the writing of MT code without engaging compiler-level gotchas?". Can the low level issues be dealt with in the short term by following certain rules, perhaps platform-specific ones, or is robust MT code ...

To thread or not to thread
Hello, I was recently reading an article on threading in python and I came across Global Interpreter Lock,now as a novince in python I was cusrious about 1.Is writing a threaded code in python going to perform well than a normal python code.If so on what basis can it performance be measured. 2.Is writing a threaded code in python better than a code written in C/C++ using PTHREADS. If someone can comment on these questions, it would be great. On 2005-07-28, Sidd <iamsidd@gmail.com> wrote: > I was recently reading an article on threading in python and I > came across Glo...

About threading.Thread
Hello guys: I have an question on threading.Thread My code is here: File1: a.py import threading import time def hello(): while True: print('hello') threads =3D threading.enumerate() for thread in threads: print(thread.getName()) time.sleep(3) def fun(): a =3D threading.Thread(target=3Dhello(), name=3D'hello') print("a file: I won't display!") a.start() File2: b.py import time from a import fun fun() print("b file: I won't display!") When I run: python b.py (python version: 2.7.6, 3.3.5, 3.4....

Segmentation fault returning value in Thread for Tcl 8.3.5/Thread 2.5 (2.1.5)
I wrote a simple "exec" function that runs the specified program in another thread, splits out the stdout and stderr output and returns asynchronously. (I attached the script and traceback from the core dump at the end of this message.) I started off using Tcl 8.3.5/Thread 2.5 (2.1.5). It seems that if the script running in the other thread returns a value using "return $result", I get a core dump. But, if I return the value using "set result", it doesn't core dump. If I use Tcl 8.4.5/Thread 2.5.2, the script throws an error condition if I use "re...

Whether Tcl_FinalizeThread release the thread special data affect other threads or not in multi-threads enviornment.
--------------21A09B54FB79E8148CDFB499 Content-Type: text/plain; charset=gb2312 Content-Transfer-Encoding: 7bit -- Alex Wang IOTA Development, Lucent Qingdao(QD), R&D Tel:(Office) +86-532-8702000 ext.5371 Email:wangtianda@lucent.com http://gdcsvr.gdc.lucent.com/~alexw --------------21A09B54FB79E8148CDFB499 Content-Type: text/html; charset=gb2312 Content-Transfer-Encoding: 7bit <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> &nbsp; <pre>--&nbsp; Alex Wang IOTA Development, Lucent Qingdao(QD), R&amp;D Tel:(Office) +86-532-...

Can single-threaded gcc be used for writing multi-threaded apps?
I 'd like to know whether single-threaded gcc can be used for: 1. Writing multithreaded C app ( gcc file.c -pthread ). 2. Writing multithreaded C++ app ( g++ file.cpp -pthread ). I will be very pleased with answers more detailed than just 'yes' and 'no'. OpenBSD 4.2, gcc 3.3.5 (propolice) Viatly wrote: > I 'd like to know whether single-threaded gcc can be used for: > 1. Writing multithreaded C app ( gcc file.c -pthread ). > 2. Writing multithreaded C++ app ( g++ file.cpp -pthread ). Short answer: YES. But just linking it with -phread library won't make ...

Will combining a single threaded app with multi-thread library cause problem?
I have a single threaded application linking with all single threaded libraries. Now, I try to link a multi-threaded library and compile the single threaded application with multi-thread flag (-mt) in Solaris. However, the application receives SIGBUS indicating "Invalid address alignment" and crashes. Will mixing the single and multiple thread cause this problem? Thanks in advance. Sagenaut sagenaut@gmail.com wrote: > I have a single threaded application linking with all single threaded > libraries. Now, I try to link a multi-threaded library and compile > the single threaded application with multi-thread flag (-mt) in > Solaris. However, the application receives SIGBUS indicating "Invalid > address alignment" and crashes. Will mixing the single and multiple > thread cause this problem? > It shouldn't. You'll have to dig further with a debugger. -- Ian Collins ...

Thread question
Here's a java problem I'm trying to work through. I wrote a program that solves a game a friend of mine calls the "Cracker Barrel Game" because he remembers it from restaraunts of that genre. There are 15 holes in a triangle with 14 pegs, as below. 0 p p p p p p p p p p p p p p You play by jumping over a peg and removing it, trying to get to just one peg. I implemented this with threads as follows: I wrote a class "game" implementing runnable and - in the run method - the object checks whether there is a valid move. If there is, it checks for all valid moves, starting another thread running game for each possible move. If not, it checks whether this sequence of moves is better than the last stored sequence of moves. To keep track of things, every time an instance of game is initialized, it increments a static variable and prints that out. When it's done, the program prints out the answer it came up with. The order in which the threads run is not gaurunteed. Since the program regards any result with just 1 peg as a perfect game, I expect it to get one of 15 acceptable answers. What I didn't expect was that the number of threads run is different every time - something like 15000 to 25000 threads. The approach I've described should create the same number of threads each time. It doesn't try to save cycles by making use of results ...

TCL built with threads, but no Thread package
Hello, I'm just getting started with TCL threads (using Brent Welch's et al excellent book). I've built a threaded TCL, but when I do package require Thread, I get an error: % puts $tcl_platform(threaded) 1 % package require Thread can't find package Thread What am I doing wrong? Thanks, Frem. Fremlins wrote: > % puts $tcl_platform(threaded) > 1 > % package require Thread > can't find package Thread > > What am I doing wrong? Is the Thread package installed on your system? -- | Don Porter Mathematical and Computational Sciences Division...

single threaded vs. multi threaded
1. Which programs lend themselves to be single threaded? 2. Which programs lend themselves to be multi threaded? 3. How to convert a multi threaded program to single threaded program? omar_hashmi786@yahoo.com wrote: > 1. Which programs lend themselves to be single threaded? > 2. Which programs lend themselves to be multi threaded? > 3. How to convert a multi threaded program to single threaded program? Sorry there are no general purpose answers to your questions. Get a book about mulitthreading and read the introduction. Normally this should help you to understand something about multithreading. On 6 Jun 2006 18:03:47 -0700, omar_hashmi786@yahoo.com <omar_hashmi786@yahoo.com> wrote: > 1. Which programs lend themselves to be single threaded? > 2. Which programs lend themselves to be multi threaded? > 3. How to convert a multi threaded program to single threaded program? Try www.amazon.com. There are at least 5 books that I know of on the subject. They'll probably give you a far more thorough treatment than you can expect on usenet, if you are looking for a serious and complete solution. A bientot Paul -- Paul Floyd http://paulf.free.fr (for what it's worth) Surgery: ennobled Gerald. omar_hashmi786@yahoo.com wrote: > 1. Which programs lend themselves to be single threaded? > 2. Which programs lend themselves to be multi threaded? > 3. How to convert a multi threaded program to single threaded program? > ...

need example of multi-threaded java pgm
Hi. I want to startup 3 threads which will access elements of a Vector and perform an action based upon the value in the vector. I want to each thread to get priority to the Vector to grab the next element in order that the particular thread completed enacting on the previous Vector element. Forinstance, Assuming each thread gets started in order.. The first three elements of the vector would get executed in order Thread 0 ==> element 0 Thread 1 ==> element 1 Thread 2 ==> element 2 However if Thread 1 finished before the others it would grab the next vector element.. Threa...

Multi-Threaded use of Tcl Interpreters
Hi, I have a multi-threaded application and I would like to use multiple Tcl interpreters (several per thread for different purposes) and have them execute independent of one another (they mainly perform lots of calculations using expr and return values to the calling thread. This all works fine until someone goofs up and causes an exception. Then the message gets printed out just fine, but later on (after all of the threads have stopped their processing) when I try to clean up the interpreters, the Tcl channels are corrupted. I think this is due to the way that I am initializing and destroying the interpreters. What I do is, rougly: in the main thread, I create an array of pointers to a data structure that has a bunch of thread specific information including the Tcl interpreters that thread will use. The pointer starts out NULL. start up the threads. When a task is sent off to a thread the thread first checks to see if it has its thread specific data - if not, create the data structure, fire up the interpreters using Tcl_CreateInterp, feed in a bunch of Tcl code and then continue on. Subsequent tasks dispatched to that thread will use the same Tcl interpreters and other data structures by accessing them via thread index the above mentioned array of pointers. At various points, the thread will select one of its Tcl interpreters, feed something to it using Tcl_EvalObjv and get the answer back using Tcl_GetObjResult. The Tcl interpreters don't need any knowledge ...

GDB waking up threads in a multi-threaded application
Hi, I really hope I have the correct newsgroup here, and if not I apologise in advance. I'm writing some multi-threaded code here for a client/server application and I had to use a read/write lock to achieve concurrency. When I left the application running over-night it hung the next day. So I started up GDB and attached to the client and then the server examining the threads present in each and the back-trace of each thread to get a better idea of where the hang occurred. After detaching GDB from the server the deadlock/hang went away and the application started working...

single threaded vs. multi threaded programming
1. What types of application are to be single threaded? 2. What types of application are to be multi threaded? 3. How to convert a multi-threaded program to single-threaded? omar_hashmi786@yahoo.com wrote: > 1. What types of application are to be single threaded? > 2. What types of application are to be multi threaded? > 3. How to convert a multi-threaded program to single-threaded? This is like asking "how do I build a bridge". It's so expansive and vague that it can only be answered with a short joke or a hundred page treatise. If you want general ...

single threaded vs multi threaded programming
1. Which programs lend themselves to be single threaded? 2. Whcih programs lend themselves to be multi threaded? 3. How to convert a multi threaded program to single threaded program? omar_hashmi786@yahoo.com wrote: > 1. Which programs lend themselves to be single threaded? > 2. Whcih programs lend themselves to be multi threaded? A program doesn't lend itself to being single- or multi-threaded. It either is or isn't. However, there might be tasks for which a single-threaded solution would be better than a multi-threaded solution, or vice versa. > 3. How to convert a mult...

How to implement thread specific timer in a multi-threaded program
Hi, Can someone provide some pointers on how to implement thread specific timer in a multi-threaded program. This is on Linux using pthreads. Any pointers would be appreciated. On Sep 27, 6:09=A0am, Deepak <dpkshe...@gmail.com> wrote: > Hi, > =A0 =A0Can someone provide some pointers on how to implement thread > specific timer in a multi-threaded program. > This is on Linux using pthreads. Any pointers would be appreciated. My advice to you would be not to do that. Associate the timer with what the thread is doing, not with the thread. DS David Schwartz <davids@webmaster.com> writes: > On Sep 27, 6:09=A0am, Deepak <dpkshe...@gmail.com> wrote: >> Hi, >> =A0 =A0Can someone provide some pointers on how to implement thread >> specific timer in a multi-threaded program. >> This is on Linux using pthreads. Any pointers would be appreciated. > > My advice to you would be not to do that. Associate the timer with > what the thread is doing, not with the thread. Yes, instead of having thread-specific timers, have any number of generic timers. cf. the POSIX.1-2001 functions setitimer(2) and getitimer(2), or the POSIX.1-2008 functions timer_settime(2) and timer_gettime(2. --=20 __Pascal Bourguignon__ On Sep 28, 3:03 pm, p...@informatimago.com (Pascal J. Bourguignon) wrote: > David Schwartz <dav...@webmaster.com> writes: > > On Sep 27, 6:09 am, Deepak <dpkshe...

Web resources about - enable-threads with multi-threaded/multi-interp app but w/o tcl thread api? #2 - comp.lang.tcl

Livefyre Enables Ads In Comment Threads
The new option lets publishers sell inventory using their current ad systems. Please visit Marketing Land for the full article.

Resources last updated: 3/13/2016 10:43:00 AM