From 7d8c51e71ad2149b63a7053f3f831857bb97a682 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 13 Oct 2008 16:01:44 +0000 Subject: [PATCH] 2008-10-13 18:01 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/vm/thread.c + added small description for hb_threadOnce() .prg function * harbour/include/hbthread.h ! do not set TLS in POCC and XCC builds when _MSC_VER macro is set This compilers also have this macro but dllspec( thread) does not work for them (at least in version 4.50.15) * harbour/utils/hbtest/rt_hvm.prg + added few tests which exploit by DMC bug. Be careful with this compiler. In some cases it gives buggy final code, f.e. try this: #include typedef struct { double dd; long long int ll; } UN; const char * cmp( UN * pU ) { return pU->dd >= pU->ll ? "OK" : "ERRROR"; } int main( void ) { UN u = { 10.50, 10 }; printf( "%s\n", cmp( &u ) ); return 0; } The same bug can be exploited also by final Harbour binaries compiled by DMC in code like: ? iif( 10.50 >= 10, "OK", "ERROR" ) I used DMC 8.42n. As long as such things will not be fixed by DMC developers this compiler is not supported by Harbour and reported problems with DMC Harbour builds will have to be ignored by us. --- harbour/ChangeLog | 41 +++++++++++++++++++++++++++++++++ harbour/include/hbthread.h | 2 +- harbour/source/vm/thread.c | 14 +++++++++++ harbour/utils/hbtest/rt_hvm.prg | 4 ++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index bd77741074..0b98791f7d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,47 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-10-13 18:01 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/vm/thread.c + + added small description for hb_threadOnce() .prg function + + * harbour/include/hbthread.h + ! do not set TLS in POCC and XCC builds when _MSC_VER macro is set + This compilers also have this macro but dllspec( thread) does + not work for them (at least in version 4.50.15) + + * harbour/utils/hbtest/rt_hvm.prg + + added few tests which exploit by DMC bug. Be careful with + this compiler. In some cases it gives buggy final code, f.e. + try this: + + #include + typedef struct + { + double dd; + long long int ll; + } UN; + const char * cmp( UN * pU ) + { + return pU->dd >= pU->ll ? "OK" : "ERRROR"; + } + int main( void ) + { + UN u = { 10.50, 10 }; + printf( "%s\n", cmp( &u ) ); + return 0; + } + + The same bug can be exploited also by final Harbour binaries + compiled by DMC in code like: + + ? iif( 10.50 >= 10, "OK", "ERROR" ) + + I used DMC 8.42n. As long as such things will not be fixed by + DMC developers this compiler is not supported by Harbour and + reported problems with DMC Harbour builds will have to be + ignored by us. + 2008-10-13 16:34 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbclass.ch * harbour/source/vm/classes.c diff --git a/harbour/include/hbthread.h b/harbour/include/hbthread.h index c57f3713a2..92dcc7eaa8 100644 --- a/harbour/include/hbthread.h +++ b/harbour/include/hbthread.h @@ -316,7 +316,7 @@ extern void hb_threadMutexUnlockAll( void ); /* enable native compiler TLS support be default for this compilers * which are known that it will work correctly */ -# if defined( _MSC_VER ) +# if defined( _MSC_VER ) && !defined( __POCC__ ) && !defined( __XCC__ ) # define HB_USE_TLS # elif defined( __GNUC__ ) && __GNUC__ >= 3 && \ defined( __GLIBC__ ) && defined( __GLIBC_MINOR__ ) && \ diff --git a/harbour/source/vm/thread.c b/harbour/source/vm/thread.c index e3f9a18741..72767a02ba 100644 --- a/harbour/source/vm/thread.c +++ b/harbour/source/vm/thread.c @@ -959,6 +959,20 @@ HB_FUNC( HB_THREADTERMINATEALL ) #endif } +/* hb_threadOnce( @ [, ] ) -> + * Execute only once. is variable which holds + * the execution status and have to be initialized to NIL. In most of + * cases it will be simple staticvariable in user code. + * When is executed by a thread all other threads which call + * hb_threadOnce() are stopped even if they use different . + * Because hb_threadOnce() uses single recursive mutex then deadlock caused + * by cross call to hb_threadOnce() from different threads is not possible. + * If thread calls hb_threadOnce() with the same variable + * recursively from then hb_threadOnce() returns immediately + * returning FALSE without executing . + * This function returns logical value indicating if it was 1-st call to + * hb_threadOnce() for given variable + */ HB_FUNC( HB_THREADONCE ) { PHB_ITEM pItem = hb_param( 1, HB_IT_ANY ); diff --git a/harbour/utils/hbtest/rt_hvm.prg b/harbour/utils/hbtest/rt_hvm.prg index 869b91789e..2b526f1a83 100644 --- a/harbour/utils/hbtest/rt_hvm.prg +++ b/harbour/utils/hbtest/rt_hvm.prg @@ -265,6 +265,7 @@ PROCEDURE Main_HVM() TEST_LINE( 2 <= 2.0 , .T. ) TEST_LINE( 2.5 <= 3.7 , .T. ) TEST_LINE( 3.7 <= 2.5 , .F. ) + TEST_LINE( 10 <= 10.50 , .T. ) TEST_LINE( .F. <= .F. , .T. ) TEST_LINE( .T. <= .F. , .F. ) TEST_LINE( .F. <= .T. , .T. ) @@ -297,6 +298,7 @@ PROCEDURE Main_HVM() TEST_LINE( 2 < 2.0 , .F. ) TEST_LINE( 2.5 < 3.7 , .T. ) TEST_LINE( 3.7 < 2.5 , .F. ) + TEST_LINE( 10.50 < 10 , .F. ) TEST_LINE( .F. < .F. , .F. ) TEST_LINE( .T. < .F. , .F. ) TEST_LINE( .F. < .T. , .T. ) @@ -329,6 +331,7 @@ PROCEDURE Main_HVM() TEST_LINE( 2 >= 2.0 , .T. ) TEST_LINE( 2.5 >= 3.7 , .F. ) TEST_LINE( 3.7 >= 2.5 , .T. ) + TEST_LINE( 10.50 >= 10 , .T. ) TEST_LINE( .F. >= .F. , .T. ) TEST_LINE( .T. >= .F. , .T. ) TEST_LINE( .F. >= .T. , .F. ) @@ -361,6 +364,7 @@ PROCEDURE Main_HVM() TEST_LINE( 2 > 2.0 , .F. ) TEST_LINE( 2.5 > 3.7 , .F. ) TEST_LINE( 3.7 > 2.5 , .T. ) + TEST_LINE( 10.50 > 10 , .T. ) TEST_LINE( .F. > .F. , .F. ) TEST_LINE( .T. > .F. , .T. ) TEST_LINE( .F. > .T. , .F. )