Files
harbour-core/tests/mt/mttest09.prg
vszakats 306fdd0446 2013-03-15 18:27 UTC+0100 Viktor Szakats (harbour syenar.net)
* package/*
  * src/compiler/harbour.y
  * src/compiler/harbour.yyc
  * src/macro/macro.y
  * src/macro/macro.yyc
  * src/pp/hbpp.1
  * tests/*/*
  * utils/*
    * stripped svn header manually

  * tests/hbdocext.hb
  * tests/lang2po.hb
  * tests/big5_gen.prg
  * tests/uc16_gen.prg
    * do not add svn ids to generated sources

  + tests/stripsvn.hb
    + added script to strip svn header from sources
2013-03-15 18:30:08 +01:00

66 lines
1.6 KiB
Plaintext

/*
* Harbour Project source code:
* demonstration/test code for using the same work area in different
* threads. Please note that this program also works when compiled
* without thread support.
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://harbour-project.org
*
*/
STATIC s_mainThreadID
proc main()
field F1
local thID, bResult
s_mainThreadID := hb_threadSelf()
/* create table */
dbCreate("_tst", { { "F1", "C", 1, 0 } } )
use _tst
while lastRec() < 10000
dbAppend()
F1 := chr( recno() )
enddo
? "main thread ID:", s_mainThreadID
thID := hb_threadStart( @thFunc() )
? "current thread ID:", thID
? "work area in use, used() =>", used(), alias()
WAIT "Press a key to detach work area"
hb_dbDetach( , {|| countRecords( {|| F1 == "A" } ) } )
? "work area detached, used() =>", used(), alias()
? "we will make some other things now..."
hb_idleSleep( 1 )
? "let's check the result"
? "request for work area"
hb_dbRequest( , , @bResult, .T. )
? "work area atached, used() =>", used(), alias()
? "query result:", eval( bResult )
close
dbDrop("_tst")
return
proc thFunc()
local bQuery, xResult
if hb_dbRequest( , , @bQuery, .T. )
xResult := Eval( bQuery )
hb_dbDetach( , {|| xResult } )
endif
return
static func countRecords( bFor )
local nCount := 0
dbGoTop()
while ! eof()
if eval( bFor )
nCount ++
endif
dbSkip()
enddo
? "!!! JOB DONE !!!" + iif( hb_threadSelf() == s_mainThreadID, ;
" (by main thread)", " (by child thread)" )
return nCount