Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » GuiLock Example broken
GuiLock Example broken [message #22793] Mon, 17 August 2009 10:35 Go to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
Hi,

I tried the GuiLock example and got the following error:

Assertion failed in d:\programs\upp-svn\uppsrc\Draw\DrawLock.cpp, line 32
sGLockLevel > 0

Whereas GuiMT example works fine.
Could it be MingW causing the troubles?

System: WinXP, MingW 4.3.0, SVN 1514

Matthias
Re: GuiLock Example broken [message #22794 is a reply to message #22793] Mon, 17 August 2009 10:36 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
I have same type of problems with MINGW and MT.
No problems with MSC or GCC on Linux

cocob
Re: GuiLock Example broken [message #22795 is a reply to message #22793] Mon, 17 August 2009 11:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12269
Registered: November 2005
Ultimate Member
masu wrote on Mon, 17 August 2009 04:35

Hi,

I tried the GuiLock example and got the following error:

Assertion failed in d:\programs\upp-svn\uppsrc\Draw\DrawLock.cpp, line 32
sGLockLevel > 0

Whereas GuiMT example works fine.
Could it be MingW causing the troubles?

System: WinXP, MingW 4.3.0, SVN 1514

Matthias


AFAIK, there was a problem with TLS variables in mingw. sGLockLevel is TLS variable...

I am sorry, but right now we cannot support MT with mingw, to my best knowledge.

Mirek
Re: GuiLock Example broken [message #22800 is a reply to message #22795] Mon, 17 August 2009 17:02 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3095
Registered: August 2008
Ultimate Member
Hello cocob/masu

Yes it happens the same to me.

I do not have any idea about MT but if you base on GuiMT sample you can do things that work.

Best regards
Koldo


Best regards
Iñaki
Re: GuiLock Example broken [message #22801 is a reply to message #22795] Mon, 17 August 2009 18:22 Go to previous messageGo to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
Hi,

I also added '-mthreads' flag to link command line and now the example works.
I think you simply forgot to add it at the time '-mthreads' was added to compile step for MingW long time ago.
A patch is applied for GccBuilder.cpp.

Matthias
Re: GuiLock Example broken [message #22802 is a reply to message #22801] Mon, 17 August 2009 19:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12269
Registered: November 2005
Ultimate Member
Nice. Thanks a lot, patch applied.

Mirek
Re: GuiLock Example broken [message #22806 is a reply to message #22802] Tue, 18 August 2009 01:38 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3095
Registered: August 2008
Ultimate Member
Hello masu

I have compiled TheIde and sample using svn 1517.

Sample now runs well with MinGW, but on closing the program I get an error. It seems to come from Windows but is in spanish (in my case).

index.php?t=getfile&id=1890&private=0

It happens the same both in Debug and Speed versions.

Best regards
Koldo
  • Attachment: Error.PNG
    (Size: 8.50KB, Downloaded 748 times)


Best regards
Iñaki
Re: GuiLock Example broken [message #22810 is a reply to message #22806] Tue, 18 August 2009 13:13 Go to previous messageGo to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
Hi Koldo,

I could reproduce your problem, but I have different behavior on different machines. I observed problems on machines with different MingW version installed.
Can you make sure the right MingW binary path is the first in your PATH env variable and then try again?

Matthias
Re: GuiLock Example broken [message #22811 is a reply to message #22810] Tue, 18 August 2009 14:45 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3095
Registered: August 2008
Ultimate Member
Hello masu

I use MinGW version 4.4.0.

Best regards
Koldo


Best regards
Iñaki
Re: GuiLock Example broken [message #22813 is a reply to message #22811] Tue, 18 August 2009 20:22 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12269
Registered: November 2005
Ultimate Member
To be fair, I had quite a lot problems to manage "exit".

It is not unlikely that MT code is broken - maybe it can crash in MSC or GCC/Linux too. It did not during my testing, but maybe somebody should test more intensely...

Mirek
Re: GuiLock Example broken [message #22829 is a reply to message #22813] Thu, 20 August 2009 17:52 Go to previous messageGo to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
Hi,

attached I provide a test package for explicit TLS using phreads.

I wanted to evaluate implicit TLS due to missing __thread storage qualification support on OpenBSD. What I discovered was a strange behavior with U++ Core package included.

It runs without problems when compiled in optimal mode without including U++ Core. But when I include Core U++ package I get segmentation faults all the time regardless if it is compiled in debug mode or optimal mode.

As far as I understand the only thing that is replaced by including Core package is heap implementation (in optimal mode) and since I use the heap to allocate and de-allocate memory for the TLS variables it is used instead of standard one. Is that right?

If I do not use heap allocated variables, but pre-allocated ones, I do not have any problems (This can be done by setting TLS_PRE_ALLOC to true).

Matthias

[Updated on: Fri, 21 August 2009 10:39]

Report message to a moderator

Re: GuiLock Example broken [message #22835 is a reply to message #22829] Fri, 21 August 2009 14:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12269
Registered: November 2005
Ultimate Member
Memory allocator uses implicit TLS, __thread (in fact, it is the cornerstone of its efficiency). If that one is replaced by something not working, it explains the issue. Have you tried with USEMALLOC.

Another thing to mention is that Thread has, at thread exit, explicit call to release per-thread associated allocator cache. If you are not using Thread, you should call MemoryFreeThread(); at the end of thread. But symptoms of this would be leaks, not crashes.

Side note: allocator only replaces new/delete, not alloc/free.

Re: GuiLock Example broken [message #22836 is a reply to message #22835] Fri, 21 August 2009 14:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12269
Registered: November 2005
Ultimate Member
BTW, it looks like you alloc tls by 'new' and free it using 'free'.

That is a receipt of failure in any case Smile

Mirek
Re: GuiLock Example broken [message #22838 is a reply to message #22836] Fri, 21 August 2009 14:19 Go to previous messageGo to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
Hi Mirek,

thanks for explanations, it seems, it was the call to free instead of delete that caused the crash ... (sorry about that).

I meant explicit TLS not implicit one in my prior post, will edit it to correct this one.

Thanks for now,
Matthias
Re: GuiLock Example broken [message #22841 is a reply to message #22838] Fri, 21 August 2009 14:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12269
Registered: November 2005
Ultimate Member
masu wrote on Fri, 21 August 2009 08:19

Hi Mirek,

thanks for explanations, it seems, it was the call to free instead of delete that caused the crash ... (sorry about that).

I meant explicit TLS not implicit one in my prior post, will edit it to correct this one.

Thanks for now,
Matthias


Actually, if correct __thread is not available, U++ allocator cannot work in MT.

Maybe you should just USEMALLOC then... In any case, to stay on the safe side, you TLS implementation should use malloc/free (and maybe then you could use such TLS to make U++ allocator work, although any positive effects will be likely diminished by slow TLS).

Mirek
Re: GuiLock Example broken [message #22843 is a reply to message #22841] Fri, 21 August 2009 14:43 Go to previous messageGo to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
luzr wrote on Fri, 21 August 2009 14:33

Actually, if correct __thread is not available, U++ allocator cannot work in MT.


I know, thats why I get problems on OpenBSD (at least I think so, at the moment).

luzr wrote on Fri, 21 August 2009 14:33

Maybe you should just USEMALLOC then... In any case, to stay on the safe side, you TLS implementation should use malloc/free (and maybe then you could use such TLS to make U++ allocator work, although any positive effects will be likely diminished by slow TLS).


Ok, thanks for the advice.

Matthias
Re: GuiLock Example broken [message #22860 is a reply to message #22843] Sun, 23 August 2009 10:37 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3095
Registered: August 2008
Ultimate Member
Hello all

Now GuiMT sample fails in the same way in MinGW as reported in GuiLock sample in Tue, 18 August 2009. It goes ok in MSC (Windows) and Gcc (Linux)

It happens in the program end.

In Debug mode I get this:

index.php?t=getfile&id=1900&private=0

emutls_destroy function is called from the exit() function.

Is MinGW the source of this problem ?

In new version 4.4.1 emutls.c file has been changed. However I have not found MinGW 4.4.1 binaries.

Best regards
Koldo
  • Attachment: demo.PNG
    (Size: 3.80KB, Downloaded 874 times)


Best regards
Iñaki
Re: GuiLock Example broken [message #22871 is a reply to message #22860] Mon, 24 August 2009 10:26 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3095
Registered: August 2008
Ultimate Member
Hello all

Good news. Twilight Dragon Media has released their GCC/mingw32 4.4.1 version (http://www.tdragon.net/recentgcc/)

I have just tried GUIMT and GUILock samples and both work.

Bad news. The samples seem to go slow. GUILock with MSC Debug goes much faster than with MinGW Speed.

The binaries I have chosen first are without dwarf-2.

Best regards
Koldo

Addendum 1:

Unfortunately there are compiling problems using dwarf-2 version
Compiling GUILock sample I get:
Quote:

In file included from C:/upp/out/Draw/MINGW.Debug.Debug_full.Gui.Mt\$bl itz.cpp:3:
C:\upp\uppsrc\Draw\DrawLock.cpp:11: error: thread-local storage not supported for this target
In file included from C:/upp/out/Draw/MINGW.Debug.Debug_full.Gui.Mt\$bl itz. sGlokLevel > 0".cpp:10:
C:\upp\uppsrc\Draw\Font.cpp:266: error: thread-local storage not supported for this target
C:\upp\uppsrc\Draw\Font.cpp:328: error: thread-local storage not supported for this target
C:\upp\uppsrc\Draw\Font.cpp:355: error: thread-local storage not supported for this target
C:\upp\uppsrc\Draw\Font.cpp:356: error: thread-local storage not supported for this target
C:\upp\uppsrc\Draw\Font.cpp:357: error: thread-local storage not supported for this target
...


They are related with thread__.

Addendum 2:

This is black magic for me: In Mt.h using always
#define thread__ __declspec(thread) 
(removing __thread) GUIMT sample works well and GUILock stops with error "Assertion failed in ... DrawLock.cpp, line 32. sGLockLevel > 0"



Best regards
Iñaki

[Updated on: Mon, 24 August 2009 11:22]

Report message to a moderator

Re: GuiLock Example broken [message #22873 is a reply to message #22871] Mon, 24 August 2009 12:23 Go to previous messageGo to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
Hi Koldo,

thank you for your investigation.

Implicit TLS (thread-local storage) that is used in U++ is not always supported, depending on Compiler and OS support.
It is declared by using
__declspec(thread)
var for MSC and
__thread
for GCC.

That is why you see problems with GUILock example since it depends on having sGLockLevel variable locally available in all threads which does not seem to be supported with dwarf-2 version.
AFAIK GuiMT example does not need to use thread-local variables, that is why it works.

I have the same problems with OpenBSD that is why I try to find a solution for systems (Compiler and OS combinations) that do not support implicit TLS.

Regards,
Matthias
Re: GuiLock Example broken [message #22901 is a reply to message #22873] Wed, 26 August 2009 09:10 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3095
Registered: August 2008
Ultimate Member
Thank you Matthias+Mirek

Finally I will left TDM 4.4.1 as non-dwarf version makes very slow programs and dwarf version with "Speed" option cannot link the programs. It seems it has to be polished.

To work I have returned to MinGW 4.4.0 using GuiMT concepts and voiding __thread in line 10 of Mt.h, so that now the programs end well without the emutls_destroy problem reported before.

I understand Mirek, but under Windows I do not want to depend only on MSC so I prefer to use something worse than GuiLock __, but more portable.

Best regards
Koldo



Best regards
Iñaki
Previous Topic: How to send msg to specific IP ?
Next Topic: Example Hello World Client/Server Broken?
Goto Forum:
  


Current Time: Mon Mar 30 11:58:47 CEST 2020

Total time taken to generate the page: 0.02139 seconds