OSX: Stack warning and freezes with two threads

BlitzMax Forums/MaxGUI Module/OSX: Stack warning and freezes with two threads

explosive(Posted 2010) [#1]
Hi altogether,

I'm currently experimenting with threads and the MaxGUI. Very basically I have to main functions that I want to run parallel. Both functions create a window and load stuff to draw.

Now I experience two major things:

1) When starting the second window, the gadgets are added to the window very slowly.
2) Without the debugger the programme freezes and with it MacOS as well. When having the debugger turned on the performance is even worse and I get a hell a lot of warnings from the NS-library. Here are the last few lines from a sample programme:
2010-02-16 17:58:18.482 pipestarter.debug.mt[611:4603] *** _NSAutoreleaseNoPool(): Object 0x457920 of class NSConcreteMutableAttributedString autoreleased with no pool in place - just leaking
Stack: (0x9335bf4f 0x93268432 0x90121784 0x90120c0d 0x900a3402 0x900a2fd5 0x900a2f5f 0x900a2ee0 0x90065b70 0x90065540 0x900653ee 0x17eb4 0x7fb9 0x5e04 0x1d3ec 0x55d8 0x447b4 0x15524b 0x92d26155 0x92d26012)
2010-02-16 17:58:18.594 pipestarter.debug.mt[611:4603] *** _NSAutoreleaseNoPool(): Object 0x489790 of class __NSFastEnumerationEnumerator autoreleased with no pool in place - just leaking
Stack: (0x9335bf4f 0x93268432 0x9006b1ae 0x9011945d 0x186fe 0x7fb9 0x5e04 0x1d3ec 0x55d8 0x447b4 0x15524b 0x92d26155 0x92d26012)
2010-02-16 17:58:18.595 pipestarter.debug.mt[611:4603] *** _NSAutoreleaseNoPool(): Object 0x481c40 of class NSDeviceRGBColor autoreleased with no pool in place - just leaking
Stack: (0x9335bf4f 0x93268432 0x1982c 0x987d 0x5f60 0x1d3ec 0x55d8 0x447b4 0x15524b 0x92d26155 0x92d26012)
2010-02-16 17:58:18.596 pipestarter.debug.mt[611:4603] *** _NSAutoreleaseNoPool(): Object 0x467130 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x9335bf4f 0x93268432 0x1939d 0x987d 0x5f60 0x1d3ec 0x55d8 0x447b4 0x15524b 0x92d26155 0x92d26012)
2010-02-16 17:58:18.596 pipestarter.debug.mt[611:4603] *** _NSAutoreleaseNoPool(): Object 0x467150 of class NSObject autoreleased with no pool in place - just leaking
Stack: (0x9335bf4f 0x93268432 0x900dfd9a 0x900ff875 0x90065495 0x900653ee 0x19784 0x987d 0x5f60 0x1d3ec 0x55d8 0x447b4 0x15524b 0x92d26155 0x92d26012)


The programme is just the following lines:
Import maxgui.drivers

SetHotKeyEvent(KEY_F5,Null)

win=CreateWindow("Main",0,0,250,ClientHeight(Desktop()),0,1)
Repeat
	event=WaitEvent()
	If event=EVENT_WINDOWCLOSE Then End
	If event=EVENT_HOTKEYHIT
		CreateThread(pipewin,Null)
	EndIf
Forever

Function pipewin:Object(data:Object)
	pwin=CreateWindow("Child",250,0,ClientWidth(Desktop())-250,ClientHeight(Desktop()),0,1)
	Repeat
		event=WaitEvent()
		If event=EVENT_WINDOWCLOSE Then FreeGadget(pwin);Return
	Forever
End Function


My questions are:
- Am I doing anything wrong?
- Is it just a bug on MacOS?
- Is there a better way to have two (or even more) windows running? TProcess sadly opens up a new dock icon and system_ halts the caller.

My system:
MacOS 10.5.8, 2x1,8Ghz Intel, 2GB Ram
BM 1.38, MaxGUI 1.36 (both just updated)

[Edit]
I let the code run on opensuse 11.2 and everything works fine. Maybe I try to port my big code with canvases and quite a few images tonight and can then report about the experiences under linux.
[/Edit]

Many thanks for your help anyway!
Simon


Brucey(Posted 2010) [#2]
Am I doing anything wrong?

As far as I know, interaction with the GUI must be handled in the main thread only.


explosive(Posted 2010) [#3]
Hi Brucey,

I just let the code run under linux. The performance is poor as well even though now exceptions are thrown.

So what's actually the best way to have more than just a single window running? Creating all gadgets and fetching all events in the main thread and only letting the update-functions run in its own thread?

Do you have experiences with that?

Cheers
Simon


jsp(Posted 2010) [#4]
In general there are two options with MaxGui.

First, you can create several windows and gadgets on top and check all events in the main thread with the standard WaitEvent() command or so. Depending on what should happen, there is no problem to do so.

Second, you can use hooks to hook one or more gadgets directly into the event-queue. Also here no problem, but it’s more complicated, though it has the advantage to be independent as it does not need an event loop.

If it will be a small tool or dialog thing I would use method one, as it is easier.
If it will be a medium to big project I would go for the second approach and try to create independent types.

To make your user response not too slow you can create a window in a hidden state during startup and then later hide and show as needed.
The gui should be handled in the main thread, you could run your ‘actions’ in the background then.


Rozek(Posted 2010) [#5]
Hmmm,

if all interaction with the GUI must be done in the main thread, how do I implement a non-blocking "requestDir" or "requestFile" then?

I just tried to invoke these functions from within a separate thread (and properly hand over the result to the main thread) which worked fine under Windows, but fails (i.e. blocks and produces those nasty _NSAutoreleaseNoPool() messages) under MacOS X

Thanks in advance for any hint (as I really want to avoid blocking under MacOS X!)