Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will outgrow your usefulness.


comp / comp.lang.tcl / Re: Crash in Itcl when using Iwidgets in multiple threads

SubjectAuthor
* Crash in Itcl when using Iwidgets in multiple threadsPetro Kazmirchuk
+* Re: Crash in Itcl when using Iwidgets in multiple threadsHarald Oehlmann
|`- Re: Crash in Itcl when using Iwidgets in multiple threadsPetro Kazmirchuk
+- Re: Crash in Itcl when using Iwidgets in multiple threadsSchelte
+- Re: Crash in Itcl when using Iwidgets in multiple threadsundroidwish
`- Re: Crash in Itcl when using Iwidgets in multiple threadsundroidwish

1
Subject: Crash in Itcl when using Iwidgets in multiple threads
From: Petro Kazmirchuk
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 23 Aug 2024 12:29 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vivid.tree7955@fastmail.com (Petro Kazmirchuk)
Newsgroups: comp.lang.tcl
Subject: Crash in Itcl when using Iwidgets in multiple threads
Date: Fri, 23 Aug 2024 14:29:53 +0200
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <va9vc0$thcj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 23 Aug 2024 14:29:52 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0a511bbb828af201f37ab023c00ca5e7";
logging-data="968083"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mrFlPd5e9TqaIcAiAcBcONWTu7geRqkQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:J/IaHAi3Yjvm00WroCZIrDPqQm8=
Content-Language: en-US
View all headers

Minimal example:

package require Thread

set thread_script {
package require Iwidgets
iwidgets::pushbutton .btn -text [thread::id]
pack .btn
after 4000 [list thread::release [thread::id]]
thread::wait
}

for {set i 0} {$i<1000} {incr i} {
thread::create -preserved $thread_script
after 500
}

This code runs 8 threads in parallel each showing an iwidget (pushbutton
or anything else, doesn't matter) and after ~1 minute it crashes with:

Unhandled exception at 0x00007FF8846DA6E4 (itcl424t.dll) in
tclsh86t.exe: 0xC0000005: Access violation reading location
0x0000000000000018.

Windows, Tcl 8.6.14, Itcl 4.2.4, Itk 4.2.6, Iwidgets 4.1.
The same crash happens when using the Itk written in pure Tcl:
https://chiselapp.com/user/rene/repository/itk/home

That's why I'm convinced the problem is in Itcl rather than Itk, and the
stack trace points to Itcl as well. Probably, there is a mutex missing
somewhere.

I didn't try to reproduce it on Linux.

I understand that both Iwidgets and Itcl are legacy that is barely
maintained, that's why I'm not raising a bug in Fossil that very few
people would notice. What I'm asking instead from a much wider audience
here is for a workaround. Is it possible to change my code somehow to
avoid the crash? Of course, preserving the basic multi-threaded
architecture.

The original code is a huge framework that can't be rewritten to
separate GUI into one main thread.

Thanks in advance,
Petro

Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 23 Aug 2024 12:52 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
Date: Fri, 23 Aug 2024 14:52:43 +0200
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <vaa0mr$r09k$1@dont-email.me>
References: <va9vc0$thcj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 23 Aug 2024 14:52:44 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3742298ef5c040b6e7dd2dfb84c1ea47";
logging-data="885044"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nYi7VZ/XGoB3J0T5UFWPd"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:syFblltHly8JAs5TCtK31pZ2HpA=
Content-Language: en-GB
In-Reply-To: <va9vc0$thcj$1@dont-email.me>
View all headers

Am 23.08.2024 um 14:29 schrieb Petro Kazmirchuk:
> Minimal example:
>
> package require Thread
>
> set thread_script {
>     package require Iwidgets
>     iwidgets::pushbutton .btn -text [thread::id]
>     pack .btn
>     after 4000 [list thread::release [thread::id]]
>     thread::wait
> }
>
> for {set i 0} {$i<1000} {incr i} {
>     thread::create -preserved $thread_script
>     after 500
> }
>
> This code runs 8 threads in parallel each showing an iwidget (pushbutton
> or anything else, doesn't matter) and after ~1 minute it crashes with:
>
> Unhandled exception at 0x00007FF8846DA6E4 (itcl424t.dll) in
> tclsh86t.exe: 0xC0000005: Access violation reading location
> 0x0000000000000018.
>
> Windows, Tcl 8.6.14, Itcl 4.2.4, Itk 4.2.6, Iwidgets 4.1.
> The same crash happens when using the Itk written in pure Tcl:
> https://chiselapp.com/user/rene/repository/itk/home
>
> That's why I'm convinced the problem is in Itcl rather than Itk, and the
> stack trace points to Itcl as well. Probably, there is a mutex missing
> somewhere.
>
> I didn't try to reproduce it on Linux.
>
> I understand that both Iwidgets and Itcl are legacy that is barely
> maintained, that's why I'm not raising a bug in Fossil that very few
> people would notice. What I'm asking instead from a much wider audience
> here is for a workaround. Is it possible to change my code somehow to
> avoid the crash? Of course, preserving the basic multi-threaded
> architecture.
>
> The original code is a huge framework that can't be rewritten to
> separate GUI into one main thread.
>
> Thanks in advance,
> Petro

Petro,
if you look here:
https://core.tcl-lang.org/itcl/timeline?udc=1&ss=v&n=&y=all&advm=0
ITCL has commits two days ago. So, there is some care.
It is a bundled package.
So it would be great to file a bug report.

Thanks,
Harald

Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
From: Petro Kazmirchuk
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 23 Aug 2024 14:18 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vivid.tree7955@fastmail.com (Petro Kazmirchuk)
Newsgroups: comp.lang.tcl
Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
Date: Fri, 23 Aug 2024 16:18:51 +0200
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <vaa5o9$udr4$1@dont-email.me>
References: <va9vc0$thcj$1@dont-email.me> <vaa0mr$r09k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 23 Aug 2024 16:18:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c9b9e3520fbb061fbe1dd6541b05699f";
logging-data="997220"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/SW9XnzH8EpJanQ3+NqG6thUWkq4kohYU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xsDOiPh7Y6BY6sFyiHLD9QRNs9s=
Content-Language: en-US
In-Reply-To: <vaa0mr$r09k$1@dont-email.me>
View all headers

On 23/08/2024 14:52, Harald Oehlmann wrote:
> Am 23.08.2024 um 14:29 schrieb Petro Kazmirchuk:
>> Minimal example:
>>
>> package require Thread
>>
>> set thread_script {
>>      package require Iwidgets
>>      iwidgets::pushbutton .btn -text [thread::id]
>>      pack .btn
>>      after 4000 [list thread::release [thread::id]]
>>      thread::wait
>> }
>>
>> for {set i 0} {$i<1000} {incr i} {
>>      thread::create -preserved $thread_script
>>      after 500
>> }
>>
>> This code runs 8 threads in parallel each showing an iwidget
>> (pushbutton or anything else, doesn't matter) and after ~1 minute it
>> crashes with:
>>
>> Unhandled exception at 0x00007FF8846DA6E4 (itcl424t.dll) in
>> tclsh86t.exe: 0xC0000005: Access violation reading location
>> 0x0000000000000018.
>>
>> Windows, Tcl 8.6.14, Itcl 4.2.4, Itk 4.2.6, Iwidgets 4.1.
>> The same crash happens when using the Itk written in pure Tcl:
>> https://chiselapp.com/user/rene/repository/itk/home
>>
>> That's why I'm convinced the problem is in Itcl rather than Itk, and
>> the stack trace points to Itcl as well. Probably, there is a mutex
>> missing somewhere.
>>
>> I didn't try to reproduce it on Linux.
>>
>> I understand that both Iwidgets and Itcl are legacy that is barely
>> maintained, that's why I'm not raising a bug in Fossil that very few
>> people would notice. What I'm asking instead from a much wider
>> audience here is for a workaround. Is it possible to change my code
>> somehow to avoid the crash? Of course, preserving the basic
>> multi-threaded architecture.
>>
>> The original code is a huge framework that can't be rewritten to
>> separate GUI into one main thread.
>>
>> Thanks in advance,
>> Petro
>
> Petro,
> if you look here:
> https://core.tcl-lang.org/itcl/timeline?udc=1&ss=v&n=&y=all&advm=0
> ITCL has commits two days ago. So, there is some care.
> It is a bundled package.
> So it would be great to file a bug report.
>
> Thanks,
> Harald
>

ok done:
https://core.tcl-lang.org/itcl/tktview/0e55608dbd661663d7efeb4dc91c1c815ab5ba6e

fingers crossed :)

Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
From: Schelte
Newsgroups: comp.lang.tcl
Organization: KPN B.V.
Date: Fri, 23 Aug 2024 14:41 UTC
References: 1
Date: Fri, 23 Aug 2024 16:41:27 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
Newsgroups: comp.lang.tcl
References: <va9vc0$thcj$1@dont-email.me>
Content-Language: en-US
From: nospam@wanadoo.nl (Schelte)
In-Reply-To: <va9vc0$thcj$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <nnd$373274b5$696c2943@65e884ea42206068>
Organization: KPN B.V.
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 16
Injection-Date: Fri, 23 Aug 2024 16:41:27 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
View all headers

On 23/08/2024 14:29, Petro Kazmirchuk wrote:
> This code runs 8 threads in parallel each showing an iwidget (pushbutton
> or anything else, doesn't matter) and after ~1 minute it crashes with:
>
> Unhandled exception at 0x00007FF8846DA6E4 (itcl424t.dll) in
> tclsh86t.exe: 0xC0000005: Access violation reading location
> 0x0000000000000018.

As far as I know, Tk isn't thread safe. So your approach is fraught with
danger to begin with. It would be better to have one thread for the GUI
and separate threads to do the work, if needed.

Schelte.

Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
From: undroidwish
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 25 Aug 2024 08:37 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: undroidwish@googlemail.com (undroidwish)
Newsgroups: comp.lang.tcl
Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
Date: Sun, 25 Aug 2024 10:37:44 +0200
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <vaeqgp$1qqhj$1@dont-email.me>
References: <va9vc0$thcj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 25 Aug 2024 10:37:45 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0d0a0b30049b28f5fc3fba0d5916536b";
logging-data="1927731"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qjOcbTHK/yMUE7QQhmeckPuKE791LnTU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:+86tVfoClzysRT9nv/ViTEO+LvY=
Content-Language: en-US
In-Reply-To: <va9vc0$thcj$1@dont-email.me>
View all headers

On 8/23/24 14:29, Petro Kazmirchuk wrote:

> ...
> That's why I'm convinced the problem is in Itcl rather than Itk, and the
> stack trace points to Itcl as well. Probably, there is a mutex missing
> somewhere.

Your hint was valuable to track down the problem. Meanwhile sebres
found a much better solution using the Tcl_Obj infrastructure, see the
respective ticket and commit in the itcl repo.

> I didn't try to reproduce it on Linux.
>
> I understand that both Iwidgets and Itcl are legacy that is barely
> maintained, that's why I'm not raising a bug in Fossil that very few
> people would notice. What I'm asking instead from a much wider audience
> here is for a workaround. Is it possible to change my code somehow to
> avoid the crash? Of course, preserving the basic multi-threaded
> architecture.

Now for the multi-threading GUI thing: IMO with the itcl fix you should
be fine on Win32. Linux (= X11) is a completely different story and in
its current state indeed not suitable for this approach. MacOS is a full
stop in this regard by design.

For X11 I've used your code snippet to tweak a setup which works for me,
see this check-in https://www.androwish.org/home/info/9b0450622edec074

The final trick was to re-use X display connections. Otherwise the
XOpenDisplay()/XCloseDisplay() in a multi-threaded program quickly
uncovers inconsistencies in Xlib/Xrender/Xft. Some more additional
locking in Tk's Xft font module (libxft isn't thread safe) was
necessary, too.

And BTW undroidwish with its X11 emulation layer ran your snippet
OOTB with the itcl fix.

BR,
Christian

Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
From: undroidwish
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 25 Aug 2024 08:44 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: undroidwish@googlemail.com (undroidwish)
Newsgroups: comp.lang.tcl
Subject: Re: Crash in Itcl when using Iwidgets in multiple threads
Date: Sun, 25 Aug 2024 10:44:11 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <vaeqss$1qs5f$1@dont-email.me>
References: <va9vc0$thcj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 25 Aug 2024 10:44:12 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0d0a0b30049b28f5fc3fba0d5916536b";
logging-data="1929391"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Tpzq7QMnj2abbhD9ku9FYY8lOAWPpfpo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:oEw7Ut2Wz7EU4AdisgBRpaUJR5w=
In-Reply-To: <va9vc0$thcj$1@dont-email.me>
Content-Language: en-US
View all headers

On 8/23/24 14:29, Petro Kazmirchuk wrote:

> ...
> The original code is a huge framework that can't be rewritten to
> separate GUI into one main thread.

If you can live with a non libxft build of Tk on X11 platforms
chances are that it's working provided the itcl fix is used.

Thus, I would start with a stock Tk built with --disable-xft.

HTH,
Christian

1

rocksolid light 0.9.8
clearnet tor