Multithreading

User avatar
Enrico Maria Giordano
Posts: 8770
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 7 times
Contact:

Multithreading

Post by Enrico Maria Giordano »

Antonio,

what do you think about this sample (xHarbour):

Code: Select all | Expand

FUNCTION MAIN()    LOCAL hThr := STARTTHREAD( @MyFunc() )    INKEY( 0 )    STOPTHREAD( hThr )    INKEY( 0 )    RETURN NILSTATIC FUNCTION MYFUNC()    WHILE .T.        THREADSLEEP( 1000 )        TONE( 440, 1 )    ENDDO    RETURN NIL


EMG
User avatar
Silvio.Falconi
Posts: 7187
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 9 times

Re: Multithreading

Post by Silvio.Falconi »

what I can do with it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Antonio Linares
Site Admin
Posts: 42655
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 67 times
Been thanked: 96 times
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: 8770
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 7 times
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: 8770
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 7 times
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
Enrico Maria Giordano
Posts: 8770
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 7 times
Contact:

Re: Multithreading

Post by Enrico Maria Giordano »

I just found that MT EXEs are slower than ST ones. :-(

Any comments?

EMG
User avatar
Antonio Linares
Site Admin
Posts: 42655
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 67 times
Been thanked: 96 times
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: 8770
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 7 times
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: 42655
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 67 times
Been thanked: 96 times
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: 8770
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 7 times
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 | Expand

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: 8770
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 7 times
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: 42655
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 67 times
Been thanked: 96 times
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: 8770
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 7 times
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: 42655
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 67 times
Been thanked: 96 times
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