From 603ad8a1fde3d8dbdcd20017a78f1fad597d0ee2 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 19 Jan 2009 21:13:58 +0000 Subject: [PATCH] 2009-01-19 22:17 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/vm/hvm.c * clone arrays and hash tables instead of coping when thread static variable is initialized + harbour/tests/mt/mttest12.prg + added demonstration/test code which illustrates thread static variables initialization --- harbour/ChangeLog | 9 +++++++ harbour/source/vm/hvm.c | 9 ++++++- harbour/tests/mt/mttest12.prg | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 harbour/tests/mt/mttest12.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index d646977e19..de8cc8a9a0 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,15 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2009-01-19 22:17 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/vm/hvm.c + * clone arrays and hash tables instead of coping when thread static + variable is initialized + + + harbour/tests/mt/mttest12.prg + + added demonstration/test code which illustrates thread static + variables initialization + 2009-01-19 21:38 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbct/ctwin.c * harbour/contrib/hbct/ctwin.h diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index a0c475ca25..825531924b 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -5984,7 +5984,14 @@ static PHB_ITEM hb_vmTSVRefRead( PHB_ITEM pRefer ) if( !pItem ) { pItem = ( PHB_ITEM ) hb_stackGetTSD( &pTSVRef->threadData ); - hb_itemCopy( pItem, &pTSVRef->source ); + if( HB_ITEM_TYPERAW( &pTSVRef->source ) & ( HB_IT_ARRAY | HB_IT_HASH ) ) + { + PHB_ITEM pClone = hb_itemClone( &pTSVRef->source ); + hb_itemCopy( pItem, pClone ); + hb_itemRelease( pClone ); + } + else + hb_itemCopy( pItem, &pTSVRef->source ); } return pItem; } diff --git a/harbour/tests/mt/mttest12.prg b/harbour/tests/mt/mttest12.prg new file mode 100644 index 0000000000..a7527b540e --- /dev/null +++ b/harbour/tests/mt/mttest12.prg @@ -0,0 +1,47 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * demonstration/test code for thread static variables + * + * Copyright 2009 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + */ + +thread static s_var1 := { "A", "B", "C" } +thread static s_var2 := { "A" => "qwe", "B" => "asd" } +thread static s_var3 := 1235.567 +thread static s_var4 := "text" + +proc main() +testvar("initial main thread values") +aadd( s_var1, "X" ) +s_var2[ "X" ] := "zxc" +s_var3 += 100000 +s_var4 := upper( s_var4 ) +testvar("modified main thread values") +hb_threadJoin( hb_threadStart( @thFunc() ) ) +testvar("modified main thread values") +return + +proc testvar( cMsg ) +? cMsg +? "s_var1:", hb_valtoExp( s_var1 ) +? "s_var2:", hb_valtoExp( s_var2 ) +? "s_var3:", hb_valtoExp( s_var3 ) +? "s_var4:", hb_valtoExp( s_var4 ) +wait +? +return + +proc thFunc() +testvar("initial child thread values") +aadd( s_var1, "Y" ) +s_var2[ "Y" ] := "abc" +s_var3 -= 500000 +s_var4 += " CHANGED" +testvar("modified child thread values") +return