Hi Przemek,

sorry for previous poor message, but it was too late and I was tired.
Now I have done a self contained sample to show what I mean.

It seems to me that SET() values are read before starting Threads, then they are separated and not shared between threads.

So if I define some SETs before starting threads it works, but once they are started all changes are ignored in thread.

I'm missing something ?

Best Regards

Francesco

------------------------

static s_lStop := .t.
static s_onceControl
static s_mutex

#define BEFORE_THREAD

PROCEDURE main()
   LOCAL lSet := .T.

   CLEAR SCREEN
   ? Version()
   ? "Main start"

#ifdef BEFORE_THREAD

   @ 12, 5 say ""
   ? "_SET_DELETED = ", Set( _SET_DELETED, lSet )
   wait

   lSet := !lSet

#endif

   hb_backgroundInit()

   @ 15, 5 say ""
   wait

   @ 16, 5 say ""
   ?
   ? "_SET_DELETED = ", Set( _SET_DELETED, lSet )
   wait

   lSet := !lSet

   @ 21, 5 say ""
   ? "_SET_DELETED = ", Set( _SET_DELETED, lSet )
   wait

return

STATIC FUNCTION hb_backgroundThread()
   WHILE !s_lStop

     hb_backgroundRun()
     hb_idleSleep( SET( _SET_BACKGROUNDTICK ) / 100000 )

   ENDDO
RETURN NIL

STATIC FUNCTION hb_backgroundInit()
   IF s_lStop
      hb_threadOnce( @s_onceControl, {||
            s_mutex := hb_mutexCreate()
            hb_mutexLock( s_mutex )
            s_lStop := .f.
            hb_threadStart( @hb_backgroundThread() )
            hb_mutexUnlock( s_mutex )
            RETURN NIL
         } )
   ENDIF
RETURN NIL

static function hb_backgroundRun()
   @ 5, 5 say ""
   ? "_SET_DELETED = ", Set( _SET_DELETED )
   ? "Do Something"
return nil



_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to