dbf in MT

279 views
Skip to first unread message

Quique

unread,
Nov 6, 2022, 4:58:18 PM11/6/22
to Harbour Users
In multithread is it possible to use de same areas by two threads at same time?

Example:

Thread 1 is in a long process, this process change records with seek, go to, replaces, etc.

Thread 2 is fired at any time and just check information from the same areas of thread 1. I don't want open the dbf files  again, because the query should show the data of the same records is in the thread 1 in this moment.

Yakano

unread,
Nov 7, 2022, 1:29:17 PM11/7/22
to Harbour Users
Not in MT, but I do something like this opening same Dbf 2 times with diferent alises (alias1, alias2, alias<n>) and it works...

Quique

unread,
Nov 7, 2022, 1:39:41 PM11/7/22
to Harbour Users

Thank you, it,  that's what I do, but I can't read the records that are being processed in the first thread, because the second one doesn't know how the first one is going, anyway, if it can't, no way.

Francesco Perillo

unread,
Nov 7, 2022, 1:47:27 PM11/7/22
to harbou...@googlegroups.com
Write the recno() of thread 1 to a shared dbf with just 1 record. Or a shared variable

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/db50d282-65b8-4e0e-b19e-96bddaa0f01fn%40googlegroups.com.

Alex Strickland

unread,
Nov 8, 2022, 2:34:03 AM11/8/22
to harbou...@googlegroups.com

Hi

In my opinion you should just be able to control access via locks as if you had two copies of the application running.

--

Regards

Alex

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/db50d282-65b8-4e0e-b19e-96bddaa0f01fn%40googlegroups.com.
--

Quique

unread,
Nov 8, 2022, 2:58:34 PM11/8/22
to Harbour Users
I dont't shure if I understand you. If you say hb_mutexLock(), no problem by this, I prefer this option, the problem is how to use the same area by two (or more) threads at the same time.

Auge & Ohr

unread,
Nov 8, 2022, 5:32:51 PM11/8/22
to Harbour Users
hi,

to use 2 x same DBF is the same as Network so your App must be "Network ready"
this have nothing to do with MT !

but i don´t understand what you are trying ... "just" slow down 1st Thread ?
every Graphic "Output" will "slow down" App even a Progressbar when use "too often"

Jimmy

Quique

unread,
Nov 9, 2022, 2:42:50 AM11/9/22
to Harbour Users
Hi

The program it's made to work in network. For this I don't have problems, and, for example, in an window program, it's possible to have more than one window using the same alias (same area). I want do it in MT. A simple example, a process that runs through the customer base, during the process you want to see in which record it goes, the second MT only show customers->name, just this, although in my case, the information could be from more than one area.

Auge & Ohr

unread,
Nov 9, 2022, 3:56:59 AM11/9/22
to Harbour Users
hi,

i do understand what you want to do but you don´t understand that it will reduce Speed "extreme" when using any "output"

Jimmy

Quique

unread,
Nov 9, 2022, 9:49:38 AM11/9/22
to Harbour Users
Hi.   The program works via the web, so the first process works autonomously without displaying information until it is finished. The query occurs if another user requests information on how the process is going, it is at that moment when I need to read the information from the records of the process that is running, this second call (second task) is the one that must read the records of the same areas (dbf) of the first process.

jb

unread,
Nov 10, 2022, 2:28:20 AM11/10/22
to Harbour Users
hi,
you might find the answer in these articles:

jb
Dne středa 9. listopadu 2022 v 15:49:38 UTC+1 uživatel Quique napsal:

Alex Strickland

unread,
Nov 10, 2022, 2:47:39 AM11/10/22
to harbou...@googlegroups.com

Hi

In http://harbourlanguage.blogspot.com/2010/04/harbour-multi-thread.html (suggested by jb) there is an excerpt from  Przemyslaw Czerpak's development log:

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

So to my understanding the threads have completely separate workareas even for the same file, and all you need is dblock() and dbunlock(), just as if you had two separate multiuser applications.

To be sure you could write a test application is 10 minutes.

--
Regards
Alex

Francesco Perillo

unread,
Nov 10, 2022, 3:47:22 AM11/10/22
to harbou...@googlegroups.com

Sorry but I think that you didn't understand what the OP is trying to do....

Thread 1:
// this job is slow....
use (bigfile)
go top
do while !eof()
    // DO SOMETHING
   skip
enddo

Thread 2:
? recno() of the dbf in thread 1

He will open the dbf in shared mode, of course, but thread 2 HAS NO IDEA of the record pointed by the RDD in thread 1 !

The only way, as I suggested, is using a variable shared by both threads, if possible, or a different dbf... here a skeleton code for dbf, a variable would be better. updating the current field every 100 records could be better... it depends on his needs.

Thread 1:
// this job is slow....
sele 1
use (bigfile) SHARED
sele 2
use temp_file SHARED
sele 1
go top
do while !eof()
    sele 2
    rlock()
    replace current with A->recno()
    unlock()
    sele 1
    // DO SOMETHING
   skip
enddo

Thread 2:
sele 1
use (bigfile) SHARED
sele 2
use temp_file SHARED
sele 1
go b->current
? "current recno():", B->current, A->name


José M. C. Quintas

unread,
Nov 10, 2022, 5:18:20 AM11/10/22
to harbou...@googlegroups.com

What about a second window to the thread?

José M. C. Quintas
--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

Auge & Ohr

unread,
Nov 10, 2022, 6:00:52 AM11/10/22
to Harbour Users
when Quique talk about Web i began to recognize what he want : Overview of used / locked Record

a.) you can use DBRLOCKLIST() to get "locked" Record OF active WorkArea
b.) when use a Thread and open DBF again and call DBRLOCKLIST() you can NOT "see" Locked Record from "Main"
c.) if you run a 2nd App and try DBRLOCKLIST() you will "see" only locked Record from 2nd App NOT from other App

ad b.)
when use a Thread and pass Result of DBRLOCKLIST() as Parameter than in Thread you got Result from "Main"

#include "HMG.CH"
#include "hbthread.ch"
REQUEST HB_GT_WIN_DEFAULT           // Console
MEMVAR aList

PROCEDURE MAIN()
LOCAL nThread
LOCAL nMainThreadID := GetCurrentThreadID()
PUBLIC aList := {}

   nThread := hb_threadStart( HB_THREAD_INHERIT_PUBLIC, @Look4Lock(), @aList )
   AttachThreadInput( nMainThreadID, HMG_ThreadHBtoWinID( nThread  ), .T. )

   USE TIMEWORK SHARE

   GOTO 10
   RLOCK()
   GetLockList(@aList)
   INKEY(3)

   GOTO 20
   RLOCK()
   GetLockList(@aList)
   INKEY(3)

   GOTO 99
   RLOCK()
   GetLockList(@aList)
   INKEY(3)

   hb_threadDetach(nThread)
RETURN

PROCEDURE GetLockList(aList)
   aList := DBRLOCKLIST()
RETURN

PROCEDURE Look4Lock(aList)
LOCAL nSize
LOCAL nCount
LOCAL nThread

   DO WHILE .T.
      nSize := LEN( aList )
      FOR nCount := 1 TO nSize
         @ 0,0 SAY "locked Record Number"
         @ nCount,0 SAY aList[ nCount ]
      NEXT
      hb_idleSleep( 0.5 )
      if INKEY() = 27
         EXIT
      ENDIF
   ENDDO
RETURN

Jimmy

Quique

unread,
Nov 10, 2022, 10:18:19 AM11/10/22
to Harbour Users
Thanks all, I think the best option is shared variable saving recno(). I don't need the list of locked records because depending on the process the main dbf may or may not be locking records. But with all the comments, I think that's the best solution.

CNavarro

unread,
Nov 16, 2022, 3:32:40 PM11/16/22
to Harbour Users
harbour/contrib/mt/mttest9.prg
  • Muestra como usar el mismo alias entre distintos hilos, usando  estas 2 funciones hb_dbRequest y hb_dbDetach. 
Reply all
Reply to author
Forward
0 new messages