Page 1 of 3

Multithreading

PostPosted: Mon May 27, 2013 6:06 pm
by Enrico Maria Giordano
Antonio,

what do you think about this sample (xHarbour):

Code: Select all  Expand view
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

Re: Multithreading

PostPosted: Mon May 27, 2013 7:06 pm
by Silvio.Falconi
what I can do with it ?

Re: Multithreading

PostPosted: Mon May 27, 2013 7:21 pm
by Antonio Linares
Enrico,

It seems what you were looking for :-)

Does it work fine ?

Re: Multithreading

PostPosted: Mon May 27, 2013 7:31 pm
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

Re: Multithreading

PostPosted: Mon May 27, 2013 7:32 pm
by Enrico Maria Giordano
Antonio,

Antonio Linares wrote:Enrico,

It seems what you were looking for :-)

Does it work fine ?


It seems so. :-)

EMG

Re: Multithreading

PostPosted: Mon May 27, 2013 7:45 pm
by Enrico Maria Giordano
I just found that MT EXEs are slower than ST ones. :-(

Any comments?

EMG

Re: Multithreading

PostPosted: Mon May 27, 2013 8:06 pm
by Antonio Linares
Enrico,

How have you measured it ?

Re: Multithreading

PostPosted: Mon May 27, 2013 9:16 pm
by Enrico Maria Giordano
Antonio,

Antonio Linares wrote:Enrico,

How have you measured it ?


With Seconds(). What else?

EMG

Re: Multithreading

PostPosted: Mon May 27, 2013 10:00 pm
by Antonio Linares
Could you provide a small example of what you tested ? thanks :-)

Re: Multithreading

PostPosted: Tue May 28, 2013 6:42 am
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 view
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

Re: Multithreading

PostPosted: Tue May 28, 2013 7:10 am
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

Re: Multithreading

PostPosted: Tue May 28, 2013 7:58 am
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

Re: Multithreading

PostPosted: Tue May 28, 2013 8:05 am
by Antonio Linares
Enrico,

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

Re: Multithreading

PostPosted: Tue May 28, 2013 8:08 am
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

Re: Multithreading

PostPosted: Tue May 28, 2013 10:18 am
by Antonio Linares
Enrico,

How many records you have on the DBF ?