Commit Graph

35 Commits

Author SHA1 Message Date
Przemyslaw Czerpak
de26bf0591 2008-11-04 02:08 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
    * removed casting to void* thread startup function passed
      as _beginthread() parameter in OS2 builds. It should be checked if
      it does not breaks GCC builds.

  * harbour/source/rtl/seconds.c
    * use getpid() instead of _getpid() in non GCC OS2 builds
2008-11-04 01:07:55 +00:00
Przemyslaw Czerpak
3fba5f0231 2008-11-03 14:08 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbthread.h
  * harbour/source/vm/thread.c
    + added ULONG _hb_gettid( void ) to OS2 builds - thanks to Maurilio

  * harbour/source/rtl/hbinet.c
    * changed a little bit the order of including header files in OS2 builds
      (blink fix for OpenWatcom OS2 builds).
2008-11-03 13:08:04 +00:00
Przemyslaw Czerpak
b89516b58d 2008-11-03 00:56 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
    + added temporary workaround for non GCC OS2 ST builds

  * harbour/source/rtl/hbmd5.c
    * casting cleanup
2008-11-02 23:55:26 +00:00
Przemyslaw Czerpak
1ad4e9c53a 2008-10-24 12:00 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/rtl/gtxwc/gtxwc.c
    * added hack for problems with some XLIB versions in heavy stress
      MT tests

  * harbour/include/hbapigt.h
  * harbour/source/vm/thread.c
    * added parameter to hb_gtAlloc() C function

  * harbour/include/hbapigt.h
  * harbour/source/rtl/hbgtcore.c
    + added hb_gtCreate() and hb_gtSwap() C functions
    + added new .prg functions:
         HB_GTCREATE( <cGtName> ) -> <pGT>
         HB_GTSELECT( <pGT> ) -> <pPrevGT>
      Using this functions is possible to create many console window
      if GT supports such possibilities (f.e. GTXWC or GTWVT) even in
      single thread programs and switch between them.

  * harbour/source/rtl/box.c
    ! fixed one of recent DISPBOX() modifications - it should use:
      hb_gtBoxEx() instead of hb_gtDrawBox() to set cursor position.

  + harbour/tests/gtwin.prg
    + added demonstration/test code for using more then one console window
      also in single thread programs.
2008-10-24 10:00:30 +00:00
Przemyslaw Czerpak
63cccbddfa 2008-10-22 19:13 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
    ! fixed memory allocation in HB_THREADWAIT() when more then 16
      threads were specified
2008-10-22 17:13:27 +00:00
Przemyslaw Czerpak
520a0a0206 2008-10-22 05:03 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbstack.h
  * harbour/include/hbgtcore.h
  * harbour/include/hbthread.h
  * harbour/include/hbapigt.h
  * harbour/source/vm/estack.c
  * harbour/source/vm/hvm.c
  * harbour/source/vm/thread.c
  * harbour/source/rtl/hbgtcore.c
    + added support for optional allocating independent console window by
      each thread. By default new thread inherits console Window from
      parent thread. But each thread can allocate its own console window
      by calling hb_gtReload( <cGtName> ) function, f.e. by:
         hb_gtReload( hb_gtVersion() )
      If GT driver supports such functionality then new it will allocate
      new console windows.
      Each console window has reference counter which is increased when
      new thread starts and decreased when hb_gtReload() is executed or
      thread terminates. When counter reach zero give console window is
      destroyed.

  * harbour/source/rtl/gtwvt/gtwvt.c
    ! use SendNotifyMessage() instead of SendMessage() to not block
      threads which inherited GT from parent thread. Why non of MS-Win
      users reported this problem?
    + added reference counter to window class for multi GT support

  + harbour/tests/mt/mttest10.prg
    + added demonstration/test code for using independent console window
      in different threads. It needs GT driver which supports such
      functionality, f.e GTXWC in *nixes or GTWVT in MS-Windows

  * harbour/tests/mt/mttest09.prg
    ! fixed typo in comment
2008-10-22 03:03:58 +00:00
Przemyslaw Czerpak
b0a88e24ff 2008-10-15 00:31 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbxvm.h
  * harbour/source/vm/hvm.c
    - removed to unused functions

  * harbour/source/vm/thread.c
    - removed unnecessary casting
2008-10-14 22:32:03 +00:00
Przemyslaw Czerpak
7d8c51e71a 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 <stdio.h>
            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:01:44 +00:00
Przemyslaw Czerpak
abfc488c1a 2008-10-12 20:31 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/hvm.c
    ! execute hb_vmThreadQuit() after hb_vmStackRelease()

  * harbour/source/vm/thread.c
    * do not destroy critical sections on exit
2008-10-12 18:31:41 +00:00
Przemyslaw Czerpak
5964eac44c 2008-10-10 22:46 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/hvm.c
    * reduced the mutex lock time in thread exit state

  * harbour/source/vm/thread.c
    ; added note about possible behavior of hb_threadSelf() function
      in one very specific situation. It's documented and expected
      behavior

  * harbour/source/rtl/hbgtcore.c
    + added support for retrieving current HB_GTI_NOTIFIERBLOCK code block
    + added support for removing HB_GTI_NOTIFIERBLOCK code block without
      setting the new one
2008-10-10 20:46:50 +00:00
Przemyslaw Czerpak
f51b6c2f24 2008-10-10 21:22 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/garbage.c
    * unblock HVM before executing destructors and releasing blocks

  * harbour/source/vm/fm.c
    ! do not call internal error with active lock when FM statistic
      is enabled

  * harbour/source/vm/thread.c
    ! stop other threads in hb_threadOnce() if the 1-st one
      executes bAction block to be sure that it will be completed
      before thread leave hb_threadOnce() function

  * harbour/source/vm/set.c
    ! do not call hb_inkeyReset() in set release. It's not necessary
      and it could change keyboard buffer size for other threads using
      the same GT driver.

  * harbour/source/vm/hvm.c
    % allocate new thread stack without lock

  * harbour/source/rtl/hbgtcore.c
  * harbour/source/rtl/gtapi.c
    * moved clipboard resetting from hbgtcore.c to gtapi.c

  * harbour/source/rtl/filesys.c
    ! do not use read/write operations with given file offset in Win9X
      which seems to not support such functionality
2008-10-10 19:23:11 +00:00
Przemyslaw Czerpak
d4b61aece8 2008-10-10 06:26 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbvm.h
  * harbour/source/vm/hvm.c
    + added hb_vmProcessDynLibSymbols() which works like
      hb_vmProcessSymbolsEx() but always mark registered modules as
      dynamic

  * harbour/source/vm/maindllp.c
    * redirect hb_vmProcessSymbolsEx() to hb_vmProcessDynLibSymbols()

  * harbour/source/vm/thread.c
    * disabled some low level locking code in non MT HVM mode
2008-10-10 04:26:42 +00:00
Przemyslaw Czerpak
a9ed741e26 2008-10-09 00:17 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbtypes.h
  * harbour/source/vm/maindllp.c
    ! updated casting for current SVN code
      [TOMERGE 1.0]

  * harbour/include/hbthread.h
  * harbour/source/vm/hvm.c
  * harbour/source/vm/thread.c
    + added .prg function
         hb_threadWait( <pThID> | <apThID>, [ <nTimeOut> ] [, <lAll> ] )
               => <nThInd> | <nThCount> | 0
      This function wait for <nTimeOut> seconds (default infinite wait)
      until one or all (controlled by <lAll> parameter) of given HVM threads
      will have finished execution in HVM area. It does not join the threads.
      It returns index to 1-st thread which has finished execution (default)
      or number of threads which has finished in given time period when lAll
      is .T.
2008-10-08 22:18:09 +00:00
Przemyslaw Czerpak
1ec50a7d81 2008-10-06 21:50 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/hvm.c
    ! fixed last commit typo in thread number allocating - all threads
      where using 0 number

  * harbour/source/vm/thread.c
    ! fixed return value in recursive call to hb_mutexLock() - was FALSE
    ! fixed typo in timeout parameter number
      should be 2 instead of 1

  * harbour/source/rtl/tobject.prg
    ! fixed init() return value - it should be ignored and current
      object should be returned

  * harbour/source/rtl/tthreadx.prg
    ! probably fixed timeout parameter use in signal:wait() method
      I guess that like other xbase++ functions it's in 1/100th of
      a second

  * harbour/include/hboo.ch
  * harbour/include/hbclass.ch
  * harbour/source/vm/classes.c
  * harbour/source/rtl/tclass.prg
    + added support for SYNC object and CLASS messages working like
      in xBase++. Please remember that all locked by thread SYNC messages
      objects and classes are unblocked automatically for the time which
      thread spends in hb_subscribe[Now]() or signal:wait()
2008-10-06 19:50:53 +00:00
Przemyslaw Czerpak
67cc2f7ebe 2008-10-06 15:30 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbthread.h
  * harbour/source/vm/thread.c
  * harbour/source/vm/hvm.c
    + add numeric HVM thread identifiers to thread structure. Now
      HB_THREADID() returns numbers in all OSes

  * harbour/include/hbexprop.h
  * harbour/include/hbexprb.c
  * harbour/source/common/expropt2.c
    + added compile time optimization for MIN() and MAX() functions

  * harbour/source/rtl/minmax.c
    * removed trailing spaces from source code
2008-10-06 13:30:47 +00:00
Przemyslaw Czerpak
3dc7a9f679 2008-10-06 11:17 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
    ! fixed typo in recent modification
2008-10-06 09:17:27 +00:00
Przemyslaw Czerpak
423391977e 2008-10-06 02:18 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/tests/speedtst.prg
    * marked T054 as memory tests

  * harbour/source/vm/hvm.c
  * harbour/source/vm/thread.c
    * added hb_threadOnce( @<onceControl> [, <bAction> ] ) -> <lFirstCall>
      This function allow to execute some code only once. It's usefull in
      MT environment for initialization.
      <onceControl> is variable which holds the execution status and have
      to be initialized to NIL. In most of cases it will be simple static
      variable in user code.
      <bAction> is optional codeblock which is executed only once (on 1-st
      call with given <onceControl>)

  * harbour/source/rtl/filesys.c
    ! do not make any file name conversions in hb_fsNameConv() if HVM stack
      is not allocated

  * harbour/source/rtl/gtcrs/gtcrs.c
    * casting
2008-10-06 00:19:10 +00:00
Przemyslaw Czerpak
38684fe9c1 2008-10-05 15:53 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
    ! fixed hb_mutexSubscribe*() in ST mode
2008-10-05 13:53:36 +00:00
Viktor Szakats
738b3391e8 2008-10-02 20:25 UTC+0200 Viktor Szakats (harbour.01 syenar hu)
* contrib/hbct/Makefile
  * contrib/hbct/common.mak
  * contrib/hbct/ctmisc.prg
  + contrib/hbct/ctdummy.prg
    * Recently added dummy CT functions moved to a separate file.

  * source/vm/thread.c
    ! Fixed warning in HB_THREADID().
2008-10-02 18:30:09 +00:00
Maurilio Longo
f25e456ddb 2008-10-02 15:54 UTC+0200 Maurilio Longo (maurilio.longo@libero.it)
* harbour/source/vm/thread.c
    * hb_ThreadID() returns 0 when built in ST mode.
2008-10-02 13:53:54 +00:00
Maurilio Longo
c2f6b15424 2008-10-02 15:50 UTC+0200 Maurilio Longo (maurilio.longo@libero.it)
* harbour/source/vm/thread.c
    + added hb_ThreadID() function which returns thread ID of current thread.
2008-10-02 13:47:59 +00:00
Przemyslaw Czerpak
cce3e73961 2008-09-29 11:18 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbvm.h
  * harbour/include/hbthread.h
  * harbour/source/vm/hvm.c
  * harbour/source/vm/thread.c
    + added hb_vmThreadRegister() funtion which allows to register new
      thread in HVM without HVM stack allocation
    + added hb_vmThreadRelease() which removes registered thread which
      does not have allocated HVM stack yet
    + added hb_threadStateNew() which returns new thread control state
      which can be used as parameter to hb_vmThreadInit(),
      hb_vmThreadRegister(), hb_vmThreadRelease()
    * register thread control state also for main thread
      Now hb_threadSelf() returns thread pointer also for main thread
    ! fixed possible race condition in hb_threadWaitForAll() and
      hb_threadTerminateAll() by using hb_vmThreadRegister() before
      starting thread.

  * harbour/source/rtl/idle.c
    * interrupt hb_idleSleep() on QUIT or BREAK requests

  * harbour/tests/mt/mttest09.prg
    * small cleanup
2008-09-29 09:19:46 +00:00
Przemyslaw Czerpak
88d4f41e4f 2008-09-26 21:28 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
    * release thread return value when is retrieve

  * harbour/common.mak
  * harbour/source/rtl/Makefile
  + harbour/source/rtl/tthreadx.prg
    + added xBase++ compatible signal class

  * harbour/source/rdd/wacore.c
    ! added missing alias setting after attaching work area

  + harbour/tests/mt/mttest09.prg
    + added test code for using the same work area in different threads
2008-09-26 19:28:54 +00:00
Przemyslaw Czerpak
acd86c6f02 2008-09-26 02:42 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
    ! fixed thread cleanup code when startthread() fails, f.e.
      OS refuse to create new thread.
2008-09-26 00:42:41 +00:00
Viktor Szakats
454b3b49e0 2008-09-23 14:38 UTC+0200 Viktor Szakats (harbour.01 syenar hu)
* contrib/hbole/ole2.c
  * contrib/hbgf/hbgfwin/winapi.c
  * contrib/hbgf/hbgfos2/os2pm.c
  * contrib/hbwin/win_ole.c
  * contrib/hbwhat/wincorec.c
  * source/rtl/do.c
  * source/rdd/workarea.c
    % hb_vmPushSymbol( hb_dynsymSymbol( p ) ) -> hb_vmPushDynSym( p )

  * contrib/hbwhat/wincorec.c
    ! WHT__GETDLGPROC() fixed.
    ! hb_vmPushSymbol( hb_itemGetSymbol( p ) ) -> hb_vmPushDynSym( p )

  * contrib/hbgf/hbgfwin/winapi.c
  * contrib/hbwhat/wincorec.c
  * contrib/hbwhat/whtmsg.c
  * contrib/hbwhat/whtbmp.c
  * contrib/hbwhat/whtcomm.c
  * contrib/hbwhat/whthead.c
  * contrib/hbwhat/whthead.c
  * contrib/hbwhat/whtkbrd.c
  * contrib/hbwhat/whtlv.c
  * contrib/hbwhat/whttext.c
  * contrib/hbwhat/whtwnd.c
  * contrib/hbwhat/whtdlg.c
  * contrib/hbwhat/whttab.c
    ! Fixed few LPARAM/WPARAM passings to be 64-bit compatible.
      (hb_parnl()/hb_parni() -> hb_parnint())

  * source/vm/thread.c
  * source/rtl/do.c
  * source/rdd/usrrdd/usrrdd.c
  * contrib/hbwhat/whtlv.c
  * contrib/hbwhat/whtfont.c
    % hb_vmPushSymbol( hb_itemGetSymbol( p ) ) -> hb_vmPush()
    ; QUESTION/TOFIX: In whtlv.c and whtfont.c this may be wrong, 
                      and hb_vmPushDynSym() could be needed instead.
                      Can someone take a look pls?
2008-09-23 12:48:23 +00:00
Przemyslaw Czerpak
afd254adc2 2008-09-22 22:08 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
    ! fixed GPF when hb_threadSelf() was executed from thread without
      allocated ID object (f.e. main thread)
2008-09-22 20:09:27 +00:00
Przemyslaw Czerpak
a8aac5cae5 2008-09-22 02:34 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbvm.h
  * harbour/source/vm/hvm.c
  * harbour/source/vm/thread.c
    + added .prg function hb_threadSelf() -> <pThID> | NIL
      It returns thread ID pointer variable or NIL when thread was
      registered without it (main thread and some 3-rd party threads
      created by C API)

  * harbour/source/vm/hvm.c
    * protect s_InitFunctions and s_ExitFunctions by mutex

  * harbour/source/common/hbverdsp.c
    * use hb_verBuildDate() instead of __DATE__ and __TIME__ in
      hb_verBuildInfo() function to report the same time in both
      cases.
2008-09-22 00:34:52 +00:00
Przemyslaw Czerpak
c1c574142e 2008-09-21 23:03 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbapi.h
  * harbour/source/vm/arrays.c
    + added hb_arrayGetPtrGC(), hb_arrayGetSymbol(), hb_arraySetSymbol()

  * harbour/include/hbapi.h
  * harbour/source/vm/dynsym.c
    + added hb_dynsymProtectEval(). Works like hb_dynsymEval() but
      keeps dynamic symbol table locked during whole execution.
      It's faster then hb_dynsymEval() but user function may not
      access dynamic symbol tbale to not cause recursive locks
    + added protection against possible dynamic symbol table resizing
      during hb_dynsymEval() by other threads.

  * harbour/include/hbapi.h
  * harbour/source/vm/memvars.c
    + added hb_memvarSaveInArray( int iScope, BOOL fCopy ) and
      hb_memvarRestoreFromArray( PHB_ITEM pArray )
    % use hb_dynsymProtectEval() in places where it's safe

  * harbour/include/Makefile
  + harbour/include/hbthread.ch
    + added header file with thread constant definitions:
         HB_THREAD_INHERIT_PUBLIC
         HB_THREAD_INHERIT_PRIVATE
         HB_THREAD_INHERIT_MEMVARS
         HB_THREAD_MEMVARS_COPY

  * harbour/include/hbthread.h
  * harbour/source/vm/hvm.c
  * harbour/source/vm/thread.c
    + added support for inheriting visible memvars from current
      thread when new thread is created. Memvars in child thread
      can be shared with parrent or they can be copied. See HB_THREAD_*
      attributes defined in hbthread.ch, f.e.:
         hb_threadStart( HB_THREAD_INHERIT_PUBLIC, @thFunc() )
      or:
         hb_threadStart( HB_BITOR( HB_THREAD_INHERIT_MEMVARS + ;
                                   HB_THREAD_MEMVARS_COPY ), ;
                          @thFunc() )
      Please note that when child thread creates new PUBLIC variable
      which didn't existed when thread was started then it's visible
      only for this thread and optionally for its child threads but
      not for parent thread.
      Please also remember that write access to shared memvars have
      to be protected by users.

  + harbour/tests/mt/mttest08.prg
    + added test code for thread memvars inheritance
2008-09-21 21:04:47 +00:00
Przemyslaw Czerpak
2f2dc484a8 2008-09-20 05:37 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/common.mak
  * harbour/source/rdd/Makefile
    ! restored dbdetach.* in makefiles

  + harbour/source/rdd/dbdetach.c
    + added file I forgot to add in previous commit

  * harbour/source/vm/thread.c
    + added support for using function name as string in HB_THREADSTART()
    + added support for thread attributes. They will be used in the future.
2008-09-20 03:37:41 +00:00
Przemyslaw Czerpak
7cc11cf5e2 2008-09-19 22:27 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/set.c
    ! fixed casting

  * harbour/contrib/xhb/xhbcopyf.c
    * replaced TABs with SPACEs

  * harbour/include/hbapirdd.h
  * harbour/source/rdd/workarea.c
  * harbour/source/rdd/wacore.c
  * harbour/source/rdd/wafunc.c
    + added support for detaching and attaching workareas

  * harbour/source/vm/hvm.c
    % minor cleanup in thread return code

  * harbour/include/hbthread.h
  * harbour/source/vm/thread.c
    * unlock HVM stack during thread join operation
    * added workaround for DosWaitThread() which seems to fail if thread
      terminated before
    ; added TOFIX note for OS2 and join code
2008-09-19 20:28:26 +00:00
Przemyslaw Czerpak
a6f735db01 2008-09-18 20:41 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
    * detach local parameters passed by reference to hb_threadStart()
      to avoid possible calling thread HVM stack corruption
2008-09-18 18:42:15 +00:00
Przemyslaw Czerpak
453b0e0cd9 2008-09-17 01:29 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/make_xmingwce.sh
  * harbour/make_xmingw.sh
    + added an option to build utility binaries in cross builds

  * harbour/source/vm/thread.c
    ! fixes in OS2 builds MT builds
2008-09-16 23:30:28 +00:00
Przemyslaw Czerpak
61647d6776 2008-09-16 14:49 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbthread.h
    + added DMC to list of compilers which can use __declspec( thread )
    + automatically use TLS for Linux and GLIBC >= 2.6 on x86* machines

  * harbour/include/hbthread.h
  * harbour/source/vm/estack.c
  * harbour/source/vm/thread.c
    ! clean up typos in OS2 builds
2008-09-16 12:49:50 +00:00
Przemyslaw Czerpak
ca21165e4b 2008-09-14 22:15 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbsetup.h
    * accept both settings: HB_FM_STATISTICS and HB_FM_STATISTICS_OFF
      without errors

  * harbour/bin/postinst.sh
    * added small trick to make HBFM lib compilation not  dependent on
      default HB_FM_STATISTIC settings

  * harbour/include/hbvm.h
  * harbour/source/vm/hvm.c
    + added C function hb_vmIsMt()

  * harbour/source/vm/cmdarg.c
    * report MT HVM status when program is executed with //INFO
      parameter

  * harbour/source/vm/fm.c
    ! fixed memory statistic MT protection in hb_xrealloc() operation

  * harbour/config/w32/owatcom.cf
    * use echo instead of echo. for non empty output.

  * harbour/include/hbextern.ch
  * harbour/source/vm/thread.c
    + added .prg function hb_threadTerminateAll() - it sends QUIT request
      to each HVM thread and waits for their termination. Can be executed
      only by main HVM thread.
2008-09-14 20:16:03 +00:00
Przemyslaw Czerpak
64f97582d9 2008-09-13 18:49 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbpp.h
  * harbour/include/hbvm.h
  * harbour/include/hbcomp.h
  * harbour/include/hbcompdf.h
  * harbour/include/hbtrace.h
  * harbour/include/hbapilng.h
  * harbour/include/hbinit.h
  * harbour/source/rtl/langapi.c
  * harbour/source/pp/ppcore.c
  * harbour/source/pp/hbpp.c
  * harbour/source/vm/itemapi.c
  * harbour/source/vm/hvm.c
  * harbour/source/common/hbver.c
  * harbour/source/common/hbtrace.c
  * harbour/source/common/expropt2.c
  * harbour/source/compiler/complex.c
  * harbour/source/compiler/hbident.c
  * harbour/source/compiler/hbfunchk.c
    * changed some declarations from 'char *' to 'const char *' and
      fixed casting for some more pedantic compilers

  * harbour/source/pp/ppcore.c
    ! fixed one typo which could cause memory leak and even GPF

  * harbour/common.mak
  * harbour/source/vm/Makefile
  * harbour/source/rtl/Makefile
  - harbour/source/rtl/set.c
  + harbour/source/vm/set.c
  * harbour/include/hbstack.h
  * harbour/source/vm/estack.c
    * moved from RTL to HVM
    * eliminated hb_set global structure
    * moved set structure to HVM stack
    + added internal function hb_setClone() which is used to create
      copy of SET structure for child threads
    * hidden HB_SET_STRUCT declaration - 3-rd part code must not access it
      directly. Dedicated hb_set*() functions should be used instead.
    + added new function:
         BOOL hb_setSetItem( HB_set_enum set_specifier, PHB_ITEM pItem )
      which allow to change some set by 3-rd party code.
      TODO: not all SETs can be changed yet - if someone have a while
            then please add code for missing ones.

  * harbour/include/set.ch
  * harbour/include/hbset.h
    + added _SET_CODEPAGE which works like _SET_LANGUAGE giving common
      interface

  * harbour/include/hbsetup.h
    + added HB_CODEPAGE_DEFAULT which works like HB_LANG_DEFAULT

  * harbour/source/vm/hvm.c
    ! fixed builds which uses non EN lang or code page modules
      by forcing linking the chosen ones

  * harbour/include/hbstack.h
  * harbour/source/vm/estack.c
  * harbour/include/hbapicdp.h
  * harbour/source/rtl/cdpapi.c
    - removed global code page variable: hb_cdp_page and moved
      code page settings to HVM stack
    + added new function hb_cdpID() which returns current code page
      character ID
    + added new functions hb_vmCDP() and hb_vmSetCDP() to get/set
      active for given thread code page structure

  * harbour/include/hbstack.h
  * harbour/source/vm/estack.c
  * harbour/include/hbapilng.h
  * harbour/source/rtl/langapi.c
    + moved lang setting to HVM stack
    + added new functions hb_vmLang() and hb_vmSetLang() to get/set
      active for given thread language module

  * harbour/include/hbvmpub.h
  * harbour/include/hbstack.h
  * harbour/include/hbapi.h
  * harbour/source/vm/estack.c
  * harbour/source/vm/dynsym.c
  * harbour/source/vm/itemapi.c
  * harbour/source/vm/memvars.c
    * changed memvar handles for HB_HANDLE to void * which is directly
      casted to PHB_ITEM - new memvar references
    * changed HB_DYNS declarations for MT mode. In MT mode HB_DYNS does
      not contain area and memvar handles which are moved to thread
      local HVM stack
    + added array for thread local memvar and area handles to HVM stack
    % eliminated global continues array with all memvars and detached locals
    % changed HB_IT_MEMVAR to use pointers to HB_ITEM directly - it resolve
      synchronization problems in MT mode and should also improve the speed
      and reduce memory usage. It should be well visible in applications which
      uses lot of detached locals.
    - removed hb_memvarsInit() and hb_memvarsFree() - they are not necessary
      now because we do not longer use array with all allocated memvars
      and detached local and private stack initialization is made
      automatically
    + added internal functions hb_dynsymGetMemvar()/hb_dynsymSetMemvar()
    + added hb_memvarGetValueBySym() for debugger
    * moved PRIVATE variable stack to HVM stack
    * eliminated all static variables in memvars module

  * harbour/include/hbstack.h
  * harbour/source/vm/estack.c
  * harbour/source/rtl/fserror.c
    * moved IO errors to HVM stack
    + added special IO error handling which works without HVM stack
      It allows to use hb_fs*() functions without allocated stack
      by 3-rd party threads.

  * harbour/source/rtl/filesys.c
    * moved hb_fsCurDir() to HVM stack with special handling to work
      with HVM stack like IO errors

  * harbour/source/rdd/workarea.c
    * allocated RDD node array in bigger peaces to reduce later RT
      reallocations in MT mode. If user want to add dynamically more
      then 64 RDDs then it should synchronize this operation himself.

  * harbour/source/rdd/wacore.c
    * moved WA list, current WA, default RDD and neteer() flag to HVM stack

  * harbour/include/hbdefs.h
    - removed HB_HANDLE declaration

  * harbour/include/hbapi.h
    - removed HB_VALUE structure - it's not longer used due to different
      memvar handling
    * updated hb_struMemvar to new memvar handling
    * replaced hb_vmIsLocalRef() and hb_memvarsIsMemvarRef() with
      hb_vmIsStackRef() which respect multiple stack and new memvar
      and static structures and location in GC mark pass.

  * harbour/include/hbstack.h
  * harbour/source/vm/estack.c
  * harbour/source/vm/hvm.c
    + added support for thread specific data located on HVM stack
      Now it's possible to allocate static variables which are
      local to thread. Such variables are allocated on HVM stack
      and automatically destroyed. To declare new TSD variable use:
         HB_TSD_NEW( <name>, <size>, <init>, <destruct> )
      <name> - name of variable which holds TSD handler
      <size> - size of TSD are which has to be allocated
      <init> - init function, executed when new TSD is allocated by thread
               (thread access given TSD 1-st time). This function receives
               void * pointer to allocated area.
      <destruct> - destructor function executed when HVM stack is destroyed
      f.e.:
         static HB_TSD_NEW( s_scrData, sizeof( HB_SCRDATA ),
                            NULL, hb_xSaveRestRelease );
      To initialize dynamically allocated TSD variable use:
         HB_TSD_INIT( <name>, <size>, <init>, <destruct> )
      Pointer to TSD can be accessed using hb_stackGetTSD( &<name> )
      where <name> is name of variable which holds TSD handler, f.e.:
         PHB_SCRDATA pScrData = ( PHB_SCRDATA ) hb_stackGetTSD( &s_scrData );
      See source/rtl/xsavescr.c as an example
      It's also possible to test if data has been already allocated for
      current thread by:
         hb_stackTestTSD( &<name> ) => pData
      it works like hb_stackGetTSD() but return NULL if current thread data
      has not been allocated yet.

  * harbour/include/hbstack.h
  * harbour/source/vm/estack.c
    * changed hb_stack location to thread local storage in MT mode
    + added functions and macros to access/assign new HVM stack members
    + changed garbage collection mark functions to work with multiple
      stacks, thread local static and memvar variables

  * harbour/source/rtl/xsavescr.c
    * use TSD data for screen buffer to make __XSAVESCREEN()/__XRESTSCREEN()
      thread independent

  * harbour/source/rtl/idle.c
    * use TSD data for idle task settings and codeblocks
    - removed hb_idleShutDown() - it's not longer necessary

  * harbour/source/rtl/setkey.c
    * use TSD data for allocated keys to make SETKEY() thread independent

  * harbour/source/rtl/math.c
    * moved math error handler, math error block, math error mode and
      math error structure to TSD

  * harbour/source/rtl/errorapi.c
    * moved error handler, error block, error launch counter and DOS error
      value to TSD

  * harbour/source/rtl/inkey.c
    * moved inkey "before" and "after" blocks to TSD

  * harbour/source/rdd/hsx/hsx.c
    * moved HSX handles array to TSD

  * harbour/include/hbapigt.h
  * harbour/source/rtl/console.c
    - removed hb_setkeyInit() and hb_setkeyExit() - they are not longer
      necessary, allocated resources will be freed by TSD destructor
      function

  * harbour/include/hbapi.h
  * harbour/source/rtl/console.c
    * removed hb_conXSaveRestRelease() - it's not longer necessary,
      allocated resources will be freed by TSD destructor function

  * harbour/source/vm/macro.c
    * moved s_macroFlags to TSD

  * harbour/source/rtl/accept.c
    * moved accept buffer to TSD

  * harbour/include/hbcomp.h
  * harbour/include/hbcompdf.h
  * harbour/include/hbxvm.h
  * harbour/source/compiler/hbmain.c
  * harbour/source/compiler/hbfix.c
  * harbour/source/compiler/hbpcode.c
  * harbour/source/compiler/hbdead.c
  * harbour/source/compiler/complex.c
  * harbour/source/compiler/genc.c
  * harbour/source/compiler/gencc.c
  * harbour/source/compiler/hbopt.c
  * harbour/source/compiler/hblbl.c
  * harbour/source/compiler/hbstripl.c
  * harbour/source/compiler/harbour.y
  * harbour/source/compiler/harbour.yyc
  * harbour/source/compiler/harbour.yyh
  * harbour/source/vm/hvm.c
    + added new PCODE HB_P_THREADSTATICS
    + added support for static variables which are local to thread:
         THREAD STATIC <varname [:= <exp>], ...>
      They work like normal static variables but each thread operates
      on its own copy.
    * added protection against possible double call to hb_xfree()
      It can happen due to wrong marking expressions as used by bison
      and executing destructors after our free code when syntax error
      appear.

  * harbour/source/rtl/perfuncs.prg
  * harbour/source/rtl/menuto.prg
  * harbour/source/rtl/getlist.prg
  * harbour/source/rtl/readvar.prg
  * harbour/source/rtl/text.prg
    * use THREAD STATIC variables to make above code MT safe

  * harbour/include/hbgtcore.h
  * harbour/source/rtl/hbgtcore.c
    + added hb_gt_BaseFree() which will release current GT pointer
      locked by hb_gt_Base() function. This function will be used
      to optional automatic GT access synchronization when threads
      share the same GT.

  * harbour/source/rtl/gtapi.c
  * harbour/source/rtl/inkeyapi.c
  * harbour/source/rtl/mouseapi.c
  * harbour/contrib/hbct/ctwin.c
    * free GT pointer by hb_gt_BaseFree()
      TODO: CTWIN is not MT safe yet - it will be updated together
            with core GT when we add multi window interface for
            thread with own console window.

  * harbour/bin/hb-func.sh
  * harbour/config/linux/gcc.cf
    + added rt lib to Linux builds

  * harbour/bin/postinst.sh
    * create MT safe version of FM stat library: fmmt

  * harbour/bin/pack_src.sh
    + added support for ZIP packing

  * harbour/include/hbapi.h
  * harbour/include/hbvm.h
  * harbour/source/vm/hvm.c
    + added hb_vmThreadInit()/hb_vmThreadQuit() functions - they initialize
      HVM for calling thread so it can execute .prg code and call HVM
      functions. They can be used by 3-rd party code threads.
    + added hb_vmUnlock()/hb_vmLock() functions which informs that
      thread will not operate on HVM structures for some time allowing
      to execute single thread only processes like GC.
    + added hb_vmThreadQuitRequest() which sends stop request to given
       thread
    + added hb_vmWaitForThreads() which stops main thread execution waiting
      for other threads
    + added hb_vmSuspendThreads() and hb_vmResumeThreads() used be GC
      to stop all HVM threads before mark/swap scan
    + added linked list of HVM stacks
    + added hb_vmTerminateThreads() used by main HVM thread in QUIT state
    * moved EXIT procedures execution from QUIT request to HVM QUIT state
      in MT mode. It may effects some non structural code which tries to
      access private variables in EXIT functions but it's much cleaner
      and understandable for user. Please remember that we guaranties
      that ALWAYS code in BEGIN SEQUENCE is _always_ executed even after
      HVM QUIT request just like destructs. Personally I think that we
      should move EXIT procedures execution also in ST mode.
    * changed startup and cleanup code for new internal structures
    * changes startup and cleanup code for MT mode
    % removed some redundant HB_ITEM type settings
    ! eliminated non MT safe code which was using reference counters
      without protection

  * harbour/common.mak
  * harbour/source/vm/Makefile
  + harbour/include/hbthread.h
  + harbour/source/vm/thread.c
    + added C level functions to manage threads and synchronization objects
      See hbthread.h for detail description. They are based on PTHREAD API
      and PTHREAD documentation can be used as reference. I intentionally
      keep this list small for easier multiplatform porting.
      Now they have been implemented for PTHREADS (POSIX threads supported by
      many different OSes), MS-Win32/64 and OS2. The OS2 version is not tested
      at all. I do not even know if it can be compiled so please make tests.
      I used Internet resources and some part of xHarbour code as documentation
      for OS2 MT API. It should be quite easy to add other platforms if necessary.
      Harbour core code needs non recursive mutexes, conditional variables and
      TLS for one pointer. If platforms does not support conditional variables
      (f.e. MS-Win or OS2) then they can be emulated using multistate semaphores.
    + added .prg functions to manage threads and synchronization objects:
         hb_threadStart( <@sStart()> | <bStart> [, <params,...> ] ) -> <pThID>
         hb_threadJoin( <pThID> [, @<xRetCode> ] ) -> <lOK>
         hb_threadDetach( <pThID> ) -> <lOK>
         hb_threadQuitRequest( <pThID> ) -> <lOK>
         hb_threadWaitForAll() -> NIL
         hb_mutexCreate() -> <pMtx>
         hb_mutexLock( <pMtx> [, <nTimeOut> ] ) -> <lLocked>
         hb_mutexUnlock( <pMtx> ) -> <lOK>
         hb_mutexNotify( <pMtx> [, <xVal>] ) -> NIL
         hb_mutexNotifyAll( <pMtx> [, <xVal>] ) -> NIL
         hb_mutexSubscribe( <pMtx>, [ <nTimeOut> ] [, @<xSubscribed> ] ) -> <lSubscribed>
         hb_mutexSubscribeNow( <pMtx>, [ <nTimeOut> ] [, @<xSubscribed> ] ) -> <lSubscribed>
      The function list should give similar to xHarbour API but they are not exactly
      the same and except of hb_mutex*() functions which should replicate xHarbour behavior.

  + harbour/source/vm/vmmt
  + harbour/source/vm/vmmt/Makefile
    + added hbvmmt library to GNU make builds.
      Non GNU make builds should be updated.

  * harbour/contrib/hbct/pos1.c
  * harbour/contrib/gtwvg/gtwvg.c
  * harbour/contrib/rddads/ads1.c
  * harbour/contrib/hbmisc/spd.c
  * harbour/contrib/hbbmcdx/bmdbfcdx.c
  * harbour/contrib/examples/rdddbt/dbfdbt1.c
  * harbour/source/vm/runner.c
  * harbour/source/vm/itemapi.c
  * harbour/source/vm/hvm.c
  * harbour/source/rtl/console.c
  * harbour/source/rtl/strcase.c
  * harbour/source/rtl/spfiles.c
  * harbour/source/rtl/defpath.c
  * harbour/source/rtl/hbgtcore.c
  * harbour/source/rtl/dateshb.c
  * harbour/source/rtl/mlcfunc.c
  * harbour/source/rtl/fstemp.c
  * harbour/source/rtl/is.c
  * harbour/source/rtl/setcolor.c
  * harbour/source/rtl/errorint.c
  * harbour/source/rtl/transfrm.c
  * harbour/source/rtl/dates.c
  * harbour/source/rtl/filesys.c
  * harbour/source/rtl/gtdos/gtdos.c
  * harbour/source/rtl/gtwin/gtwin.c
  * harbour/source/rtl/gtwvt/gtwvt.c
  * harbour/source/rtl/gtxwc/gtxwc.c
  * harbour/source/rtl/gttrm/gttrm.c
  * harbour/source/rtl/gtpca/gtpca.c
  * harbour/source/rtl/gtcgi/gtcgi.c
  * harbour/source/rtl/gtcrs/gtcrs.c
  * harbour/source/rtl/gtstd/gtstd.c
  * harbour/source/rtl/gtsln/gtsln.c
  * harbour/source/rtl/gtsln/gtsln.h
  * harbour/source/rdd/dbf1.c
  * harbour/source/rdd/sdf1.c
  * harbour/source/rdd/delim1.c
  * harbour/source/rdd/dbcmd.c
  * harbour/source/rdd/hbdbsort.c
  * harbour/source/rdd/workarea.c
  * harbour/source/rdd/dbffpt/dbffpt1.c
  * harbour/source/rdd/dbfcdx/dbfcdx1.c
  * harbour/source/rdd/dbfntx/dbfntx1.c
  * harbour/source/rdd/hsx/hsx.c
  * harbour/source/rdd/hbsix/sxfname.c
    * use API functions instead of direct accessing to hb_cdp_page or hb_set

  * harbour/source/rtl/fstemp.c
  * harbour/source/rtl/fssize.c
  * harbour/source/rtl/hbffind.c
  * harbour/source/rtl/filesys.c
    * encapsulate potentially slow IO operation inside
      hb_vmUnlock()/hb_vmLock() calls to allow other thread GC
      activation

  * harbour/contrib/hbnf/fttext.c
    ! fixed casting

  * harbour/contrib/gtwvg/gtwvg.h
    - removed #include <comctl32.h> - my MinGW and MinGW/CE instalations do
      not have them. If it exists in some newer ones then it has to be
      covered by #if version checking.

  * harbour/source/vm/dynsym.c
    - removed hb_dynsymLog() and hb_dynsymMemvarHandle()
    * modified code to be MT safe and improved speed of some operations
    * added MUEXT protection for global dynamic table access

  * harbour/include/hbapi.h
  * harbour/source/vm/garbage.c
    * changed to work with MT HVM
    * changed to work with new memvar structures and thread local static and
      memvar variables
    * added MUEXT protection for linked block lists
    + added parameter to hb_gcCollectAll() which will force GC activation
      in MT mode by temporary suspending all executed threads.
    + added logical parameter to HB_GCALL() functions which is passed to
      hb_gcCollectAll()

  * harbour/source/vm/fm.c
    * added MUEXT protection for FM statistic module
    * added MT protection for reference counters. For platforms
      which supports atomic incrmenetation/decrementation (f.e.
      Interlocked*() functions in MS-Win) such operations are
      used. For other it's MUTEX protection. It gives MT safe
      readonly access for HVM complex variables without user
      synchronization. The MUTEX protection can cause some speed
      overhead so it's good to define MT safe version of
      HB_ATOM_INC()/HB_ATOM_DEC() in hbthread.h if given platform
      has them. Now they are defined only for Windows. For other
      platforms We can define can define them in assembler for some
      most popular CPUs in the future.

  * harbour/source/vm/classes.c
    * changed class definition array. Now it keeps pointers to class
      structures.
    * In MT mode allocated at HVM startup big enough array for class
      definitions to avoid later RT reallocations. It effectively eliminates
      MUTEX synchronization for class structure access.
    * protect by MUTEX code for new class creation

  * harbour/source/debug/dbgentry.c
    * eliminated hbvmopt.h and direct accessing to HVM structures

  * harbour/source/rtl/gtclip.c
    * protect with MUTEX access to internal clipboard data

  * harbour/source/rdd/nulsys/nulsys.c
    + added hb_rddCloseAll()

  + harbour/tests/mt
  + harbour/tests/mt/mttest01.prg
  + harbour/tests/mt/mttest02.prg
  + harbour/tests/mt/mttest03.prg
  + harbour/tests/mt/mttest04.prg
  + harbour/tests/mt/mttest05.prg
  + harbour/tests/mt/mttest06.prg
  + harbour/tests/mt/mttest07.prg
    + added some demonstration/test small MT programs written
      using Harbour language. Some of them can be also compiled
      by xHarbour but xHarbour does not pass any of my tests in
      real multi-CPU machine so do not expect they will work
      correctly.

   Harbour threads needs OS threads support. Each Harbour thread is directly
   mapped to OS thread. It's not very efficient on some older system where
   cost of thread creation and/or task switching is very expensive but it
   should not be bigger problem for modern OS-es which can support threads
   in practice nearly in user space only.
   I haven't touched Harbour function calling convention which comes from
   Clipper. It means that we do not pass pointer to VM to each functions
   like CLIP or xBase++. To resolve the problem I have to use thread local
   storage (TLS) where such pointer is kept. If platform does not support
   TLS then it can be emulated by us. Anyhow the speed of accessing TLS
   data and extracting HB_STACK poitner is critical for performance.
   Some compilers depending on used hardware and OS give native support
   for TLS (f.e. __thread keyword in GCC/BCC or __declspec( thread ) in MSVC).
   This should give optimal performance. On other Harbour uses TLS functions
   like TlsGetValue() (MS-WIN) or pthread_getspecific() (PTHREAD) are used.
   OS2 gives quite interesting TLS functionality which seems to be quite fast
   though it will be interesting to know how it is iplemented internally for
   real multi CPU machines (if it depends on CPU exception then the
   performance will be bad). We need TLS only for one pointer to HB_STACK
   structure.
   I haven't added any tricks like HB_THREAD_STUB in xHarbour to reduce
   the cost of TLS access. If it will be necessary for some platform the we
   can add it.
   Except TLS Harbour threads needs OS support for non recursive mutexes or
   critical sections and conditional variables. If platforms does not support
   conditional variables (f.e. MS-Win or OS2) then they can be emulated using
   multistate semaphores. I intentionally didn't create code which may need
   recursive mutexes. The non recursive ones are often faster and some
   platforms may not support recursive mutexes so they will have to be
   emulated by us.
   Harbour uses reference counters for complex variables. It means that even
   readonly access to complex item causes internal write operations necessary
   to increment/decrement its reference counter. To make such readonly access
   MT safe we have to make incrementation and decrementation with result
   checking atomic. By default it's done by mutex inside vm/fm.c but some
   platforms have native support for atomic inc/dec operations, f.e. 
   Interlocked*() functions in MS-Win. If they are available then such
   functions should be used to not reduce the performance by mutex call
   very often used functions. For many CPUs it should be quite easy to
   implement such atomic inc/dec functionality in assembler. F.e. for
   GCC and x86@32 it may looks like:

      static __inline__ void hb_atomic_inc32( volatile int * p )
      {
         __asm__ __volatile__(
            "lock incl %0"
            :"=m" (*p) :"m" (*p)
         );
      }

      static __inline__ int hb_atomic_dec32( volatile int * p )
      {
         unsigned char c;
         __asm__ __volatile__(
            "lock decl %0"
            "sete %1"
            :"=m" (*p), "=qm" (c) :"m" (*p) : "memory"
         );
         return c == 0;
      }

   and then it's enough to define in hbthreads.h:
      #define HB_ATOM_INC( p )    hb_atomic_inc32( ( volatile int * ) p )
      #define HB_ATOM_DEC( p )    hb_atomic_dec32( ( volatile int * ) p )

   Probably I'll make it for some most popular CPUs in the future.
   In Harbour each thread which wants to call HVM functions have to allocate
   it's own HVM stack. It's done hb_vmThreadInit(). The HVM stack is freed
   by calling hb_vmThreadQuit(). This functions can be called also by 3-rd
   party threads if they want to call HVM functions or execute .prg code.
   Calling HVM functions without allocated stack will cause GPF.
   I moved most of static variables to HVM stack to make them thread
   local. But some of them like FS errors have their own alternative
   copy which is used when thread does not allocate HVM stack. It allows
   to use hb_fs*() functions without HVM stack but programmer have to
   know that error codes return by hb_fs*Error() functions can be
   overwritten by other threads which also didn't allocated HVM stack.
   To execute garbage collector scan and mark pass it's necessary to
   stop other HVM threads. Otherwise the scan may give false results.
   It's also possible to not stop threads but protect with mutex all
   operations on GC items but it will probably cause performance reduction
   and will force some other modifications. Maybe I'll implement it
   in the future.
   I didn't use any OS level thread KILL or CANCEL calls. All HVM threads
   have to be cleanly removed without any resource leaks.
   QUIT command terminate only calling thread. If main (startup) HVM
   thread call QUIT then it sends QUIT request to all existing threads.
   In QUIT state ALWAYS statements and destructors are executed.
   New thread is created by:
      hb_threadStart( <@sStart()> | <bStart> [, <params,...> ] ) -> <pThID>
   The returned value is a pointer to internal thread structure which
   can be used in JOIN or DETACH operations. Each thread should be Joined
   or DETACHED to avoid resource leaks. If programmer does not store
   <pThID> or all instances of <pThID> are destroyed then thread is
   automatically detached. I do not know clear method of thread detaching
   in OS2. If some OS2 users knows it then plase update vm/hbthread.c.
   When thread terminates then all locked by this thread mutexes are
   released.
   Each thread uses its own memvars (PRIVATEs and PUBLICs) and work areas.
   When new thread is created then it inherits from parent thread:
      - code page
      - language
      - SETs
      - default RDD
   error block is initialized to default value by calling ERRORSYS()
   and PUBLIC variable GetList := {} is created.
   The following objects are initialized to default value:
         - error block
         - math error handler and math error block
         - macro compiler features setting (hb_setMacro())
           or move them to SETs.
   We can think about inheriting them. It's also possible to add
   inheriting of all visible memvars but I do not know it's good
   idea.

   Compilation and linking:
   For MT mode HVM library should be compiled with HB_MT_VM macro.
   GNU make automatically creates hbvmmt library which should be
   linked with Harbour MT programs instead of hbvm.
   Non GNU make files should be updated.
   If given compiler support TLS then you can try to set HB_USE_TLS
   to force using native compiler TLS support. Now it's enabled by
   default only for BCC. For Linux and GCC builds it may depend also
   on used GLIBC version. In older system there is no TLS support
   at all or TLS works only for shared binaries so I haven't enabled
   it. If you will test some other compiler then please add default
   native TLS support for them in hbthread.h
   Users using hb* scripts can simply use -mt switch when they want
   to create MT program, f.e.:
      hbmk -n -w3 -es2 -mt mttest01.prg

   There are still some minor things which should be done but I'll
   do them later. Current state seems to be fully functional.
   The most important and still missing is our own file lock server
   for RDD synchronization in POSIX systems. Kernel internally
   recognize POSIX locks by PID and file i-node - not PID and file
   handle. It means that the same file open more then once by one
   process shares locks. Because POSIX locks can be overwritten
   then we do not have any synchronization between aliased workareas
   or threads using the same table in *nixes. We have to make
   synchronization ourselves. I'll create such lock server ASAP.

   Please test and enjoy using Harbour threads.
2008-09-13 16:53:45 +00:00