2014-04-01 12:33 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)

* src/rtl/filebuf.c
    ! unlock HVM stack before locking local mutex and calling hb_fs*()
      functions which also unlocks HVM. It fixes possible deadlock condition
      when hb_gcAll( .T. ) is executed.

  * include/hbapi.h
  * src/vm/garbage.c
    ! changed mark function semantic.
      Adding support for user defined mark function I created race condition
      in MT GC code. It happens because blocks marked as deleted were not
      scanned by GC mark code so their subitems where not accessible.
      To fix it we have to change mark function semantic. Now mark function
      can be executed also for blocks currently deleted. It means that GC
      block destructor should clean references to just removed items and
      subblocks. The best place to make it is clearing pointers to GC blocks
      just after hb_itemRelease() or hb_gcRefFree().
      It is save to clean the reference just before hb_itemRelease() or
      hb_gcRefFree() but only for the single block passed to these functions.
      It is not save to clear reference to more then one block and then
      execute above functions.
    + check reference count after destructor execution for all blocks
      not only arrays - warning it may exploit some wrong C code.
    - removed not longer used hb_gcRefCheck() function.

  * include/hbvm.h
  * src/vm/hvm.c
    + added new internal function hb_vmLockForce()
    ! fixed to mark GC blocks with active threads

  * src/vm/thread.c
  * include/hbthread.h
    % modified sync mutexes used by xBase++ signal class emulation
      to not use item array internally
    * updated mutex destructor to new GC mark semantic
    ! mark GT items if GT is bound with thread item
    ! fixed mutex notify/subscribe code to not change GC items
      when HVM stack is unlocked
    ! use hb_vmLockForce() to eliminate potential deadlock
    + added new C function hb_threadEnterCriticalSectionGC().
      It should be used instead of hb_threadEnterCriticalSection()
      in code which manipulates GC items inside critical section.
      It's slower but eliminates possible deadlock condition.
      Please remember that remember that both functions cannot
      be used for the same mutex. So if it's necessary to use
      hb_threadEnterCriticalSectionGC() in one place then it
      has to be used in all others when the same mutex is locked.

  * src/vm/arrays.c
  * src/vm/codebloc.c
  * src/vm/hashes.c
  * src/rtl/hbgtcore.c
  * contrib/hbcurl/core.c
  * contrib/hbexpat/core.c
    * updated destructors to new GC mark semantic

  * contrib/hbxpp/dllx.c
    ! fixed destructor for pointer item created by DllPrepareCall()
      Now it respects reference counter.
    ; added note about real behavior of library handle destructor,
      I haven't changed existing code behavior but maybe it should
      be done.

  * contrib/xhb/hbserv.c
  * src/debug/dbgentry.c
  * src/rdd/wacore.c
    ! fixed possible deadlocks by using hb_threadEnterCriticalSectionGC()
      instead of hb_threadEnterCriticalSection().

  * contrib/hbmemio/memio.c
    ! slightly modified hb_memfsDirectory() code to avoid race condition
      without using hb_threadEnterCriticalSectionGC()

  * src/vm/fm.c
    % reduce the lock range in HB_FM_STAT builds

  * src/rtl/hbsocket.c
    ! added missing HVM stack unlocking in hb_socketSelect() function

  * src/rtl/gtxwc/gtxwc.c
    ! added few missing locks for version compiled with HB_XWC_XLIB_NEEDLOCKS

  * src/rdd/dbtotal.prg
    * allow to use symbols instead of codeblocks
    * modified Harbour extension which uses ordKey() as default group
      signature to work also without index. In such case all records
      are summarized into single one.

  ; Most of above modifications were critical for stability of MT programs.
    They should allow to activate GC in any place.
This commit is contained in:
Przemysław Czerpak
2014-04-01 12:33:17 +02:00
parent 8f73524d34
commit 7349602fcb
23 changed files with 542 additions and 327 deletions

View File

@@ -607,7 +607,6 @@ extern void hb_vmIsStackRef( void ); /* hvm.c - mark all local variables a
extern void hb_vmIsStaticRef( void ); /* hvm.c - mark all static variables as used */
extern void hb_gcReleaseAll( void ); /* release all memory blocks unconditionally */
extern void hb_gcRefCheck( void * pBlock ); /* Check if block still cannot be access after destructor execution */
extern HB_COUNTER hb_gcRefCount( void * pAlloc ); /* return number of references */
#if 0

View File

@@ -375,6 +375,7 @@ extern HB_EXPORT HB_BOOL hb_atomic_dec( volatile HB_COUNTER * pCounter ); /*
/* Critical sections or fast non recursive MUTEXes */
extern HB_EXPORT void hb_threadEnterCriticalSection( HB_CRITICAL_T * critical );
extern HB_EXPORT void hb_threadEnterCriticalSectionGC( HB_CRITICAL_T * critical );
extern HB_EXPORT void hb_threadLeaveCriticalSection( HB_CRITICAL_T * critical );
/* conditional variables */

View File

@@ -175,6 +175,7 @@ extern HB_EXPORT void hb_vmPushItemRef( PHB_ITEM pItem ); /* push item refer
extern HB_EXPORT HB_BOOL hb_vmIsMt( void ); /* return HB_TRUE if HVM is compiled with thread support */
extern HB_EXPORT void hb_vmLock( void ); /* lock VM blocking GC execution by other threads */
extern HB_EXPORT void hb_vmLockForce( void ); /* lock VM blocking GC execution by other threads, ignore GC request */
extern HB_EXPORT void hb_vmUnlock( void ); /* unlock VM, allow GC execution */
#ifdef _HB_API_INTERNAL_
extern HB_EXPORT HB_BOOL hb_vmSuspendThreads( HB_BOOL fWait ); /* (try to) stop all threads except current one */