Multithreading

User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Multithreading

Post by Enrico Maria Giordano »

Antonio,

what do you think about this sample (xHarbour):

Code: Select all

FUNCTION MAIN()

    LOCAL hThr := STARTTHREAD( @MyFunc() )

    INKEY( 0 )

    STOPTHREAD( hThr )

    INKEY( 0 )

    RETURN NIL


STATIC FUNCTION MYFUNC()

    WHILE .T.
        THREADSLEEP( 1000 )
        TONE( 440, 1 )
    ENDDO

    RETURN NIL
EMG
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Multithreading

Post by Silvio.Falconi »

what I can do with it ?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Multithreading

Post by Antonio Linares »

Enrico,

It seems what you were looking for :-)

Does it work fine ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multithreading

Post by Enrico Maria Giordano »

Silvio,
Silvio.Falconi wrote:what I can do with it ?
I'm experimenting a way to make wait animations smooth even with loops without SysRefresh() inside them.

EMG
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multithreading

Post by Enrico Maria Giordano »

Antonio,
Antonio Linares wrote:Enrico,

It seems what you were looking for :-)

Does it work fine ?
It seems so. :-)

EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Multithreading

Post by Antonio Linares »

Enrico,

How have you measured it ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multithreading

Post by Enrico Maria Giordano »

Antonio,
Antonio Linares wrote:Enrico,

How have you measured it ?
With Seconds(). What else?

EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Multithreading

Post by Antonio Linares »

Could you provide a small example of what you tested ? thanks :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multithreading

Post by Enrico Maria Giordano »

Antonio,
Antonio Linares wrote:Could you provide a small example of what you tested ? thanks :-)
Something like this:

Code: Select all

FUNCTION MAIN()

    LOCAL nSec

    LOCAL cVal

    USE MYTABLE

    nSec = SECONDS()

    WHILE !EOF()
        cVal = FIELD -> myfield
        SKIP
    ENDDO

    ? "Assign and skip", SECONDS() - nSec

    CLOSE

    INKEY( 0 )

    RETURN NIL
Here I get ST: 31 MT: 41!

EMG
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Multithreading

Post by StefanHaupt »

Enrico,

just to understand, what could be the advantages using MT instead of ST ? What functions could be put in threads ?

Im my understanding a database application is a single thread application with single tasks, e.g. browsing a dbf or searching in a dbf. What can be done, to get simultaneous tasks ?

Stefan
kind regards
Stefan
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multithreading

Post by Enrico Maria Giordano »

Stefan,
StefanHaupt wrote:Enrico,

just to understand, what could be the advantages using MT instead of ST ? What functions could be put in threads ?

Im my understanding a database application is a single thread application with single tasks, e.g. browsing a dbf or searching in a dbf. What can be done, to get simultaneous tasks ?

Stefan
Don't know. I just need something to get smooth wait animations during loops without SysRefresh() in them.

EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Multithreading

Post by Antonio Linares »

Enrico,

Thanks for your example, what source code had you running on the second thread ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Multithreading

Post by Enrico Maria Giordano »

Antonio,
Antonio Linares wrote:Enrico,

Thanks for your example, what source code had you running on the second thread ?
Nothing. I created no threads. Just link vmmt.lib and cw32mt.lib in.

EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Multithreading

Post by Antonio Linares »

Enrico,

How many records you have on the DBF ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply