Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The world is no nursery. -- Sigmund Freud


devel / comp.lang.tcl / Re: tcl thread creation; c++ std::thread vs Tcl_CreateThread

SubjectAuthor
* tcl thread creation; c++ std::thread vs Tcl_CreateThreadRalf Fassel
`* Re: tcl thread creation; c++ std::thread vs Tcl_CreateThreadsaitology9
 `* Re: tcl thread creation; c++ std::thread vs Tcl_CreateThreadPhillip Brooks
  `- Re: tcl thread creation; c++ std::thread vs Tcl_CreateThreadRalf Fassel

1
tcl thread creation; c++ std::thread vs Tcl_CreateThread

<ygao7l8g3bm.fsf@akutech.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22331&group=comp.lang.tcl#22331

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: tcl thread creation; c++ std::thread vs Tcl_CreateThread
Date: Wed, 21 Jun 2023 18:58:21 +0200
Lines: 21
Message-ID: <ygao7l8g3bm.fsf@akutech.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net ebvBOSb2w2les5n1PwgQ9QO4EtS6zEETPaJGOBv3ZOxs1Trio=
Cancel-Lock: sha1:iOhcVRm3eY9LZq3/Vh/BIMiMbHE= sha1:68txVig8FzWshfPkMeYQ+8kqMqM=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Wed, 21 Jun 2023 16:58 UTC

tcl 8.6.13, Linux and Windows.

I have an application which currently uses c++ std::thread() to create
new threads¹ , and then uses some TCL C API which does not require an
interp.

I wonder whether that is safe to do, or whether it is *required* to use
Tcl_CreateThread() instead to create the new threads.

My main concern is the thread specific data which might get accessed by
TCL under the hood in the C API. Looking at the relevant code it seems
that the TSD is initialized in a 'safe' way every time the functions
need to access it (
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
...
)
R'
---
¹ using c++ std::thread is more convenient when it comes to
specifying the startup-c++ object member function

Re: tcl thread creation; c++ std::thread vs Tcl_CreateThread

<u71q7s$3bf79$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22332&group=comp.lang.tcl#22332

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: tcl thread creation; c++ std::thread vs Tcl_CreateThread
Date: Thu, 22 Jun 2023 11:43:56 -0400
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <u71q7s$3bf79$1@dont-email.me>
References: <ygao7l8g3bm.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 22 Jun 2023 15:43:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b6811d396c6050cb63e781674361c484";
logging-data="3521769"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ILXyJx54R4KfrYAw7uP6R"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:bG11HLvkKKzVCgGmXkJ2M1e4BfU=
Content-Language: en-US
In-Reply-To: <ygao7l8g3bm.fsf@akutech.de>
 by: saitology9 - Thu, 22 Jun 2023 15:43 UTC

On 6/21/2023 12:58 PM, Ralf Fassel wrote:
> tcl 8.6.13, Linux and Windows.
>
> I have an application which currently uses c++ std::thread() to create
> new threads¹ , and then uses some TCL C API which does not require an
> interp.
>
> I wonder whether that is safe to do, or whether it is *required* to use
> Tcl_CreateThread() instead to create the new threads.
>

If you are not using or activating Tcl's thread mechanism in some way,
it should play with C++'s threads just fine. This is what Tcl was first
designed to do: be a tool command language for your C++ application :-)

Re: tcl thread creation; c++ std::thread vs Tcl_CreateThread

<fc2dfe67-1ec1-4fc2-9ce3-917125e5279en@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22386&group=comp.lang.tcl#22386

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:4ae3:0:b0:635:dabe:98 with SMTP id cp3-20020ad44ae3000000b00635dabe0098mr6074qvb.4.1689263454841;
Thu, 13 Jul 2023 08:50:54 -0700 (PDT)
X-Received: by 2002:a05:6808:1785:b0:3a3:6f6a:17b5 with SMTP id
bg5-20020a056808178500b003a36f6a17b5mr2324519oib.9.1689263454590; Thu, 13 Jul
2023 08:50:54 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 13 Jul 2023 08:50:54 -0700 (PDT)
In-Reply-To: <u71q7s$3bf79$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=192.94.38.34; posting-account=SiRO5QoAAAAilq1etV9Podc0rHvm5sum
NNTP-Posting-Host: 192.94.38.34
References: <ygao7l8g3bm.fsf@akutech.de> <u71q7s$3bf79$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fc2dfe67-1ec1-4fc2-9ce3-917125e5279en@googlegroups.com>
Subject: Re: tcl thread creation; c++ std::thread vs Tcl_CreateThread
From: philbrks@gmail.com (Phillip Brooks)
Injection-Date: Thu, 13 Jul 2023 15:50:54 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1591
 by: Phillip Brooks - Thu, 13 Jul 2023 15:50 UTC

The main thing you have to be sure of is that if you do create an interpreter, it must run in the same thread that created it and it must be destroyed in the same thread that created it. Since you say you are using interfaces that don't require an interpreter, I think you are safe. If you want to use an interpreter, you can do that, but you just have to keep track of the thread to interpreter relationship.

Re: tcl thread creation; c++ std::thread vs Tcl_CreateThread

<ygafs5qho03.fsf@akutech.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=22389&group=comp.lang.tcl#22389

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: tcl thread creation; c++ std::thread vs Tcl_CreateThread
Date: Fri, 14 Jul 2023 10:54:20 +0200
Lines: 23
Message-ID: <ygafs5qho03.fsf@akutech.de>
References: <ygao7l8g3bm.fsf@akutech.de> <u71q7s$3bf79$1@dont-email.me>
<fc2dfe67-1ec1-4fc2-9ce3-917125e5279en@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net nUkmC1ahYx3jtH+QqP4KSwXtgEDp587MRwAGX8XKAB9EDL3eY=
Cancel-Lock: sha1:WY+HUNwrmNKo/qQ8mKKoRF0rHfY= sha1:8X/Hf8QOQ4+4Ecvut2bHouZ1jx0= sha256:cBSFR0HJNKiHX8RDrhpMw3JbGnlDXngi938/JSd1G9M=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Fri, 14 Jul 2023 08:54 UTC

* Phillip Brooks <philbrks@gmail.com>
| The main thing you have to be sure of is that if you do create an
| interpreter, it must run in the same thread that created it and it
| must be destroyed in the same thread that created it. Since you say
| you are using interfaces that don't require an interpreter, I think
| you are safe. If you want to use an interpreter, you can do that, but
| you just have to keep track of the thread to interpreter relationship.

I think in that case (using an interp in a second thread) I would go the
script level thread creation anyway, where you get it all "for free".

My use case is asynchronous reading data from Tcl_Channels (sockets)
which are created in main thread and transferred to the new thread via
Tcl_CutChannel/Tcl_SpliceChannel (the reading must take place regardless
of whether the main thread is blocked somehow, so fileevents are not an
option). The thread-specific data structs which are used to manage the
Tcl_Channels behind the scenes are initialized as required by TCL - a
really Good Thing¹.

TNX
R'
---
¹ http://www.catb.org/jargon/html/G/Good-Thing.html


devel / comp.lang.tcl / Re: tcl thread creation; c++ std::thread vs Tcl_CreateThread

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor