Multithreads with FWH
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Hello!
http://www.codeproject.com/KB/threads/c ... ading.aspx
http://www.codeproject.com/KB/threads/c ... xx679159xx
http://www.codeproject.com/KB/threads/S ... ation.aspx
Regards, Roman
Simple Multithreaded Application in pure C, Win32 and MFCAntonio Linares wrote: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
http://www.codeproject.com/KB/threads/c ... ading.aspx
There are also some useful comments:Selvam is very much interested in sharing his knowledge with his peers and has been awarded as a Microsoft India Community Star in 2004
http://www.codeproject.com/KB/threads/c ... xx679159xx
Thread Synchronization for BeginnersAdditionally, I would recommed to everyone who wants to learn about multithreading to read more than one article. Most articles that I've read are missing some important points; so by reading several of them, you should get the whole picture. This article, for example, doesn't mention the most important aspect of multithreading: synchronization. Additionally, reading different articles provides you with different techniques and approaches.
Especially in a complicated field like multithreading, the more you know, the better it is.
http://www.codeproject.com/KB/threads/S ... ation.aspx
Regards, Roman
© I'm not patented!
Re: Multithreads with FWH
Hello,
I was wondering if the multi-threading capability of xHarbour has advanced to a usable form.
I am using Harbour/xHarbour9.01 and BCC55
I tried to compile and run the samples mttest.prg and client.prg in the ..\xharbour\test directories. I get:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
mttest.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_HB_FUN_STARTTHREAD' referenced from D:\FIVETECH\XHARBOUR\TESTS\MTTEST.OBJ
Error: Unresolved external '_HB_FUN_WAITFORTHREADS' referenced from D:\FIVETECH\XHARBOUR\TESTS\MTTEST.OBJ
* Linking errors *
I then add in the the thread libraries vmmt.lib, rtlmt.lib, ppmt.lib, rddmt.lib, dbfntxmt.lib and dbcdxmt.lib and get:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
mttest.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '__endthreadex' referenced from D:\FIVETECH\XHARBOUR\BETA\LIB\VMMT.LIB|thread
Error: Unresolved external '__beginthreadex' referenced from D:\FIVETECH\XHARBOUR\BETA\LIB\VMMT.LIB|thread
* Linking errors *
Is there any library(s) that I can use to resolve these two funcion calls.
Thanks, Angelo.C
I was wondering if the multi-threading capability of xHarbour has advanced to a usable form.
I am using Harbour/xHarbour9.01 and BCC55
I tried to compile and run the samples mttest.prg and client.prg in the ..\xharbour\test directories. I get:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
mttest.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_HB_FUN_STARTTHREAD' referenced from D:\FIVETECH\XHARBOUR\TESTS\MTTEST.OBJ
Error: Unresolved external '_HB_FUN_WAITFORTHREADS' referenced from D:\FIVETECH\XHARBOUR\TESTS\MTTEST.OBJ
* Linking errors *
I then add in the the thread libraries vmmt.lib, rtlmt.lib, ppmt.lib, rddmt.lib, dbfntxmt.lib and dbcdxmt.lib and get:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
mttest.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '__endthreadex' referenced from D:\FIVETECH\XHARBOUR\BETA\LIB\VMMT.LIB|thread
Error: Unresolved external '__beginthreadex' referenced from D:\FIVETECH\XHARBOUR\BETA\LIB\VMMT.LIB|thread
* Linking errors *
Is there any library(s) that I can use to resolve these two funcion calls.
Thanks, Angelo.C
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Multithreads with FWH
Angelo,
Please try to link Borland cw32mt.lib instead of cw32.lib
Please try to link Borland cw32mt.lib instead of cw32.lib
Re: Multithreads with FWH
Hello Antonio,
Thank you for your suggestion. I linked in cw32mt.lib => links OK. But when it runs under Windows XP (SP3) I get the following the standard XP "encountered a problem" window saying:
"mttest.exe has encountered a problem and needs to close. We are sorry for the inconvenience. etc etc etc "
Has anyone else run this test programme (mttest.prg under xHarbour) successfully using Win XP (SP3)?
Best Regards, Angelo.C
Thank you for your suggestion. I linked in cw32mt.lib => links OK. But when it runs under Windows XP (SP3) I get the following the standard XP "encountered a problem" window saying:
"mttest.exe has encountered a problem and needs to close. We are sorry for the inconvenience. etc etc etc "
Has anyone else run this test programme (mttest.prg under xHarbour) successfully using Win XP (SP3)?
Best Regards, Angelo.C
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Multithreads with FWH
Angelo,
No, we have not tested it, as we tend to support functionalitites that are available for both Harbour and xHarbour, as we keep FWH compatible with both of them.
Once multithreading is fully functional for both compilers, then we will recommend it and support it from FWH
No, we have not tested it, as we tend to support functionalitites that are available for both Harbour and xHarbour, as we keep FWH compatible with both of them.
Once multithreading is fully functional for both compilers, then we will recommend it and support it from FWH
Re: Multithreads with FWH
Antonio,
In that case, I will put on hold any code I need that requires multi-threading and change my design to accommodate new approaches to overcome this limitation.
Hopefully you will not leave it too long to implement multi-threading in both Harbour and xHarbour. That capability makes the code much more useful.
I want to compile and run my code that I have written in FWH with xHarbour since I really like the programming extensions that are available in xHarbour. It looks like it would make my code easier to write; be in line with "newer programming constructs" and be more versatile in interfacing with other programming languages such as c/c++.
Best Regards, Angelo.C
In that case, I will put on hold any code I need that requires multi-threading and change my design to accommodate new approaches to overcome this limitation.
Hopefully you will not leave it too long to implement multi-threading in both Harbour and xHarbour. That capability makes the code much more useful.
I want to compile and run my code that I have written in FWH with xHarbour since I really like the programming extensions that are available in xHarbour. It looks like it would make my code easier to write; be in line with "newer programming constructs" and be more versatile in interfacing with other programming languages such as c/c++.
Best Regards, Angelo.C
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Multithreads with FWH
Angelo,
If you review all the work done lately on Harbour, you will be greatly surprised
Both compilers are very powefull, thats why we want to support and keep compatibility for both of them.
If you review all the work done lately on Harbour, you will be greatly surprised
Both compilers are very powefull, thats why we want to support and keep compatibility for both of them.
Re:
Dear Reinaldo,reinaldocrespo wrote: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.
I dug this old topic because right now I need the notification event of ADS9.1 to my FWH apps..
I'm using background processing with xharbour but these functions are making the app sluggish and not really multi-threading..
Can we revive this topic..
Regards,
Frances
Kind Regards,
Frances
Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Frances
Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
- reinaldocrespo
- Posts: 918
- Joined: Thu Nov 17, 2005 5:49 pm
- Location: Fort Lauderdale, FL
Re: Multithreads with FWH
Frances;
Hi.
Threads is the natural way to consume a server message. The information about threading with xharbour is somewhat shady or at least confusing to me. Fortunately I "discovered" a way to listen to ADS server messages w/out spawning a new thread. Although it works for me (at least for now), I will eventually want to experiment with threads from xharbour. I will appreciate any info you finally come up with. Here is my trick:
sp_WaitForEvent() allows a client to synchronously wait for an event notification to be sent by the server. If an event notification for the specified event has already been sent, then this will return immediately (and that is the heart of my trick). In other words, the event notification does not have to occur while this procedure is actively waiting. This means that an application can check for an event periodically and use a small (or zero) timeout period. I set a fw-timer that executes the ADS stored procedure sp_WaitForEvent() with zero timeout period.
In a nutshell, I'm polling every x seconds for the event message. Once the message is received, I then trigger the desired action.
I've learned to look for ways to solve problems and sometimes I simply figure a work-around. I know this is not exactly what we are looking for, but for now it yields the desired results. I hope this helps.
Take care,
Reinaldo.
Hi.
Threads is the natural way to consume a server message. The information about threading with xharbour is somewhat shady or at least confusing to me. Fortunately I "discovered" a way to listen to ADS server messages w/out spawning a new thread. Although it works for me (at least for now), I will eventually want to experiment with threads from xharbour. I will appreciate any info you finally come up with. Here is my trick:
sp_WaitForEvent() allows a client to synchronously wait for an event notification to be sent by the server. If an event notification for the specified event has already been sent, then this will return immediately (and that is the heart of my trick). In other words, the event notification does not have to occur while this procedure is actively waiting. This means that an application can check for an event periodically and use a small (or zero) timeout period. I set a fw-timer that executes the ADS stored procedure sp_WaitForEvent() with zero timeout period.
In a nutshell, I'm polling every x seconds for the event message. Once the message is received, I then trigger the desired action.
I've learned to look for ways to solve problems and sometimes I simply figure a work-around. I know this is not exactly what we are looking for, but for now it yields the desired results. I hope this helps.
Take care,
Reinaldo.
Re: Multithreads with FWH
I have about 50 DBF's, and I delete and create again the index for each DBF at the first run of the day. Will multi-thread increase the speed? Since the threads don't call any visual component it'll no cause any trouble with fivewin right?
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
Re: Multithreads with FWH
Dear Mr. Reinaldo,reinaldocrespo wrote:Frances;
Hi.
Threads is the natural way to consume a server message. The information about threading with xharbour is somewhat shady or at least confusing to me. Fortunately I "discovered" a way to listen to ADS server messages w/out spawning a new thread. Although it works for me (at least for now), I will eventually want to experiment with threads from xharbour. I will appreciate any info you finally come up with. Here is my trick:
sp_WaitForEvent() allows a client to synchronously wait for an event notification to be sent by the server. If an event notification for the specified event has already been sent, then this will return immediately (and that is the heart of my trick). In other words, the event notification does not have to occur while this procedure is actively waiting. This means that an application can check for an event periodically and use a small (or zero) timeout period. I set a fw-timer that executes the ADS stored procedure sp_WaitForEvent() with zero timeout period.
In a nutshell, I'm polling every x seconds for the event message. Once the message is received, I then trigger the desired action.
I've learned to look for ways to solve problems and sometimes I simply figure a work-around. I know this is not exactly what we are looking for, but for now it yields the desired results. I hope this helps.
Take care,
Reinaldo.
I used this pseudo code
Code: Select all
...
created another ADS handle for the event notification
...
update trigger has been created to table.. ' EXECUTE PROCEDURE sp_SignalEvent('tablename', FALSE, 0);'
...
Set( _SET_BACKGROUNDTASKS, .T. )
...
nTask := HB_BackGroundAdd( {|| uEvent() }, 5000, .F. ) //add to background task,
...
HB_BackGroundActive( nTask, .T. )
...
created 'EXECUTE PROCEDURE sp_CreateEvent( 'tablename', 0 );'
...
function uEvent()
created 'EXECUTE PROCEDURE sp_WaitForAnyEvent(0,0,2)'
...
here after the sp_WaitForAnyEvent ends..
how can I call a UDF? or how to know EventCount or EventName?
return
Im using ads 9.1
what's your solution?
Best Regards,
Frances
Kind Regards,
Frances
Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Frances
Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Re: Multithreads with FWH
Dear Mr. Reinaldo,
I GOT IT!
the return of sp_WaitForAnyEvent() in SQLALIAS are SQLALIAS->eventname and SQLALIAS->eventcount..
now if SQLALIAS->eventcount > 0 then call my UDF..
you made me think hard for this huh... hehehe
Thanks for the help and idea.
Best Regards,
Frances
I GOT IT!
the return of sp_WaitForAnyEvent() in SQLALIAS are SQLALIAS->eventname and SQLALIAS->eventcount..
now if SQLALIAS->eventcount > 0 then call my UDF..
you made me think hard for this huh... hehehe
Thanks for the help and idea.
Best Regards,
Frances
Kind Regards,
Frances
Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Frances
Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Re: Multithreads with FWH
Dear All,
The problem now is the "2nd" thread..
Frances
The problem now is the "2nd" thread..
Frances
Kind Regards,
Frances
Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Frances
Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
Re: Multithreads with FWH
I Need to do this, but the StartThread and WaitThread is not recognized
Code: Select all
procedure RodaTabelas()
Local i := 0, aDbfs := {}, cTime := Time()
aAdd(aDbfs,"ESTOQUE")
aAdd(aDbfs,"CAIXA")
aAdd(aDbfs,"PEDIDOS")
aAdd(aDbfs,"TITULOS")
//-- Open my DBFS and return an array with the Alias of each opened
aDbfs := OpenDbfs(aDbfs)
if .not. aDbfs[1]
Dbcloseall()
Return nil
end
For i := 1 to Len(aDbfs)
StartThread({||RodarDbf(aDbfs[i])})
end
WaitForThreads()
Msg("Rodou todos!;Tempo: " +AllTrim(Str(TimeFromStart(cTime))))
Return nil
Procedure RodarDbf(cDBF)
Select(cDbf)
DbGoTop()
While !Eof()
DbSkip()
end
Return
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6