Page 1 of 3

Multithreads with FWH

Posted: Sat Mar 22, 2008 3:47 am
by César E. Lozada
Can they be implemented with FWH + xHarbour + BCC55?

If the answer is yes, who may help me?

Threads.prg exist into FWH\Samples but class Thread isn't into any library and no source code is found.

Thanks in advance.
César Lozada

Posted: Sat Mar 22, 2008 6:13 am
by Antonio Linares
César,

samples\thread.prg is just for Xbase++, not for Harbour/xharbour.

xharbour multithreading support is not fine. We are waiting for it to get improved and fully working.

Once there is a good support for threads in Harbour/xHarbour, then we will be able to adapt FWH to multithreading.

Multithreads with FWH

Posted: Sun Mar 23, 2008 7:39 pm
by César E. Lozada
Antonio:

Thanks so much for your very prompt answer.

I started this topic because StartThread(), StopThread() and WaitForThreads() work fine with console applications in xHarbour. But they cause a GPF with FWH.

Posted: Sun Mar 23, 2008 8:34 pm
by Antonio Linares
César,

I don't know for sure if threads support have been improved lately in xHarbour. Please read these comments from Przemek about threads implementation in xHarbour:

http://www.matrixlist.com/pipermail/har ... 02426.html

"... Of course the MT mode like in xHarbour can be added in a day or two but IMHO it's only waste of time as long as all internal structure will not be MT safe."

so it may work in console mode but it may not be robust enough for GUI apps that require multiple events support. Anyhow..

What do you need the threads for ? Maybe we can provide you an alternative way to do what you need.

Also keep in mind that you can use low level C language multithreading as it is 100% supported by the C compiler.

Multithreads with FWH

Posted: Mon Mar 24, 2008 11:19 pm
by César E. Lozada
Thanks again, Antonio.

DbSetFilter() is a time consuming function, but it is still faster than going from the top to the bottom (one record each time) into a large database. I'd like to execute a call to dbSetFilter() without losing the posibility of using a progress bar or an estimated time indicator. When filtering, the entire applications hangs up until filter is finished.

I thought in using multithreads to start the dbSetFilter() call, so I keep control on the application until it's done.

Maybe you have a better idea. Whatever it is, it will be welcome.

Regards
César Lozada

Posted: Mon Mar 24, 2008 11:32 pm
by Antonio Linares
César,

Have you considered to use a conditional index instead of DbSetFilter() ?

It will be much faster, and also, you can display a progress bar meanwhile the conditional index is created, without having to use multithreading.

Posted: Tue Mar 25, 2008 5:47 am
by César E. Lozada
No. I had not considered this option.

I'll take a look.

Thanks a lot.

Posted: Tue Mar 25, 2008 6:04 am
by Otto
Antonio,
would you be so kind to show how you make a conditional index.

For example I have a database test.dbf and a text.cdx.
What are the steps to make a conditional index?
Thanks in advance
Otto

Posted: Tue Mar 25, 2008 6:25 am
by nageswaragunupudi
Mr Otto

Simple conditional index.

INDEX ON <expr> TAG <tagname> FOR <forcond>

Full syntax:
INDEX ON <indexExpr> ;
[TAG <cIndexName>] ;
[TO <cIndexFile>] ;
[FOR <lForCondition>] ;
[WHILE <lWhileCondition>] ;
[ALL] ;
[NEXT <nNumber>] ;
[RECORD <nRecNo>] ;
[REST] ;
[EVAL <bBlock>] ;
[EVERY <nInterval>] ;
[UNIQUE] ;
[ASCENDING|DESCENDING] ;
[USECURRENT] ;
[ADDITIVE] ;
[CUSTOM] ;
[NOOPTIMIZE] ;
[TEMPORARY] ;
[USEFILTER] ;
[EXCLUSIVE]

But if you are using DBFCDX, your filters are optimized and better you do not attempt creating conditional indexes.

If you want the filters to be optimized, you should be having regular indexes built on the fields, which are included in your filter expression.

Because your applications are multiuser, there are special issues you should consider while creating on the fly conditional indexes. Every index created should be in a different folder. Also some conditional indexes are not updated by further modifications of other users.

If you plan your indexes properly the speed of optimized filters overweigh the time taken for building on the fly conditional indexes. My advice is to plan your indexes properly and rely on the DBFCDX's optimization instead of creating indexes within the application and avoid dealing with issues specific to temporary indexes.

Slowness of filters and the need for creation of temporary indexes are relevant when you use DBFNTX.

Posted: Tue Mar 25, 2008 6:43 am
by nageswaragunupudi
> Also keep in mind that you can use low level C language multithreading as it is 100% supported by the C compiler.

I would be interested to know how to use C language multi-threading within a xHarbour + FWH application.

My need for multi-threading is very simple. I show browses of large tables from ADS server. I also show totals of certain columns in the footers. I get the totals using ADS Sql ( eg. SELECT SUM(DUES) FROM CUSTOMER WHERE <cond> ). The number of rows in the browse depend upon the options specified by the user. If the rows are too many the Sql query for totals take some time upto 30 secs. I do not want the user to wait.

I like to show the browse, make the sql query in another thread, and when the answer is ready refresh the footers.

ADS does not support Async queries ( ace32 or oledb). So that option is ruled out.

I think we do not know how far xharbour, adsrdd and fwh are multithread-safe. In any case I think adsrdd is not multithread compatible. If I know how to use C language multi threading within FWH + xHarbour application, I can write appropriate C code to use ACE32.DLL to query the server.

Without using multi-theads, I am aware I have a few other options, but I am more interested in using the multi-thread approach, if it is possible.

By the way, ADS Serverside filters work like miracle even with hundreds or users simultaneously accessing huge tables with million rows.

Posted: Tue Mar 25, 2008 8:01 am
by Otto
Mr. NagesWaraRao,
Thank you for your answer. I see “miracles don’t exist” considering all you wrote.

Regards,
Otto

Posted: Tue Mar 25, 2008 9:40 am
by Antonio Linares
Nageswararao,

Using the Windows API: ( CreateThread() )
http://msdn2.microsoft.com/en-us/librar ... S.85).aspx

Without using the Windows API:
http://en.wikipedia.org/wiki/Beginthread

Posted: Tue Mar 25, 2008 1:37 pm
by Gale FORd
[TEMPORARY] option automatically creates unique index in temporary directory and deletes it for you.

I also combine range with temporary index with the [USECURRENT] option.

Conditional index with CDX

Posted: Tue Mar 25, 2008 2:16 pm
by ukoenig
Hello Otto

I using Index-files for Filters with cdx
In a network i have done this :

The user can create his own index for a filter.
The index got the name of the Netuser-name.

My customer is satisfied and there are no problems at all
in a network.

Regards
Uwe

Posted: Thu Apr 10, 2008 5:51 pm
by reinaldocrespo
Antonio/All;

Here is another example where threads could be very useful:

Suppose you have an xbrowse on a table of real time data, and while you have the browse in idle mode, someone inserts a new record to the table that pertains the data you are browsing. At the very least it would be nice to show a red dot somewhere to alert the user that he needs to refresh the browse to see newly inserted records.

So far I've been doing this with timers, but it is very inefficient and awkard at best.

This could be done with threads by having the app issue an "event" and have the browsing app listen for that specific threaded-event. ADS 9 adds support for notifications. A notification could be used on this example to inform a client application that data in a critical table has changed. The client app can then use this information to refresh the browse or turn a red dot somewhere without pausing to re-read the table every n seconds for critial updates. ie... no polling.

But ADS notifications are blocking calls (the call does not complete until a signal is received) therefore we would need to issue a new thread to attend this notifications and act accordingly all while the rest of the app goes on processing keystokes or whatever else.

Would you or someone else mind helping a bit more on how to use the C calls for multithreads from a fw app? I'd certainly like to test event notifications with ADS.

Thank you,


Reinaldo.