Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips > Additional Libraries
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Additional Libraries Users contributed libraries.
This sub-forum is only available to licensed users.


Threading library for optimising compiler


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-18-2008, 03:18 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default Threading library for optimising compiler

The introduction of the true compiler for Basic4PPC opens up some avenues previously closed. One of these is the ability to write threads in Basic4PPC code rather than only being able to do this in a library.

Some/most of you will know that a thread is a separate flow of program execution. Basic4PPC normally has only one thread, the GUI (Graphical User Interface) thread that, not surprisingly, handles the user interface (and everything else). Using this library you can create additional threads that operate (apparently) in parallel alongside each other and the GUI thread.

Threads can be useful to keep the user interface alive while performing a long sequence of computations. For instance my Flite speech dll for the device runs on the GUI thread and while it is speaking you can't do anything else. Included is an example of running it on a thread so you can set it off and leave it to run and carry on user interaction. You need FliteDevice.dll and fliteDLL.dll in the app folder on the device.
Speech library for the DEVICE!
Compile ThreadTestDevice.sbp optimised for device with FliteDevice.dll and Threading.dll in the desktop app folder and transfer the resulting exe and Threading.dll to the device app folder.

The library protects itself if it finds itself running in a legacy mode so hopefully you can't crash your app whilst playing! I'll produce a help with more info later. However there is a load of comment in the ThreadTest app to hopefully give you enough information to try it out - should you dare!

EDIT :-I've updated demo source as per dzt comment below. Also I just noticed a minor issue in my workarounds to issue warnings when running in legacy mode (where it doesn't work anyway). I don't quite understand the problem at the moment but it doesn't really matter as it is cosmetic really. Just shows you can't do enough testing before release

EDIT :- Update to version 1.1 to warn politely (as always intended) rather than throw an error when any of the RunLocked calls were used in legacy mode.

EDIT : - Updated to 1.2 with Process object added.

EDIT : - Updated to 1.3 with support for module name prefixes for the thread Sub. Help and source included. Demo sources are in 6.50 format but the library is compatible with all Basic4ppc 6.xx releases.
Attached Files
File Type: zip Threading1.3.zip (30.8 KB, 33 views)

Last edited by agraham : 10-15-2008 at 03:36 PM. Reason: Updated zip
Reply With Quote
  #2 (permalink)  
Old 01-18-2008, 04:41 PM
dzt's Avatar
dzt dzt is offline
Basic4ppc Veteran
 
Join Date: May 2007
Location: Greece
Posts: 353
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Excelent!!!

A lot of knowledge is hidden here. And of course a lot of work

PS.
You should immediately turn "Check for unassigned / unused variables" on.
Try to run ThreadTest.sbp in debug mode
__________________
Dimitris Zacharakis
http://www.terracom.gr
Reply With Quote
  #3 (permalink)  
Old 01-18-2008, 05:00 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by dzt View Post
You should immediately turn "Check for unassigned / unused variables" on
Thanks dzt. I keep doing that - turning it off for testing then forgetting to turn it back on! Zip modified.
Reply With Quote
  #4 (permalink)  
Old 01-20-2008, 10:04 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Help now added to the original post. As well as documenting the library it includes a brief introduction to threads and processes.
Reply With Quote
  #5 (permalink)  
Old 01-21-2008, 03:19 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Library version 1.2 and updated help posted to original post. This version changes the name of the "Threader "object to "Thread" as I didn't like the original name and it's my library and I can do what want with it Otherwise there are no changes to the Thread object.

Added is a Process object which provides the facility that several people have asked for in the past. This is the ability to start a program (process) and know when it has finished. The Shell statement in B4PPC starts a program (process) but that is all. The Process object here can start a program, provide an Event when it terminates and can forcibly terminate it if required.
Reply With Quote
  #6 (permalink)  
Old 01-23-2008, 09:57 AM
dzt's Avatar
dzt dzt is offline
Basic4ppc Veteran
 
Join Date: May 2007
Location: Greece
Posts: 353
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by agraham View Post
...This version changes the name of the "Threader "object to "Thread" as I didn't like the original name and it's my library and I can do what want with it ...


I feel the need to say again how useful is this library, as there are many b4ppc functions taking long time to finish (FTP, Image processing etc.) and until then it is not so elegant to have the UI frozen.

I also should say that I love Process object.
__________________
Dimitris Zacharakis
http://www.terracom.gr

Last edited by dzt : 01-23-2008 at 10:14 AM.
Reply With Quote
  #7 (permalink)  
Old 02-11-2008, 05:33 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,313
Default

I'm about to use this lib for the first time, so before i do i need to ask just one thing...
I need to thread a timer...
is this thread fired as a single sub? (timer1_tick)???
__________________
Paulo Gomes
Porto, Portugal

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD

DLL Version Listing
Reply With Quote
  #8 (permalink)  
Old 02-11-2008, 05:45 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by Cableguy View Post
I need to thread a timer...
Can I ask why? Actually this is not possible due to the nature of what a timer is. Tell me what you need and perhaps we can see how to achieve it.
Reply With Quote
  #9 (permalink)  
Old 02-11-2008, 06:00 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,313
Default

I am writing an "alert" progam, in wich the user will enter a series of data including a date field...
in the mean time the program ( i have thought of an "external"program...), will, twice a day, as setted by the user, check if the date entered above matches the Today date, and if true, pop-up an Alert....But it must not halt the execution...
So what the best way to go?
__________________
Paulo Gomes
Porto, Portugal

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD

DLL Version Listing
Reply With Quote
  #10 (permalink)  
Old 02-11-2008, 06:19 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Two possibilities spring to mind.

For both possibilities I would suggest using a timer with a fairly long interval to check whether it is the right time to start one of these checks then :-

a) Start another timer or reset the original timer's interval to be shorter, say 500mS or so. Do the data checks in the timer code but structure the code so that it, for example, checks one set of data, saves where it has got to in one or more global variables, then exits the timer picking up the data to check the next set in the next timer tick, saving and exiting again, and so on till complete.

b) Use the timer code to start a separate thread that does the checking in a long code loop without returning. If you want to display the alerts from within that code you would need to use a timer event as shown in the sample app. Alternatively you could build some global variables with the alert data and then set a global flag when the thread completes that the timer could check for and then display whatever is needed.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Threading Mr_Gee Basic4ppc Wishlist 0 09-23-2008 08:57 PM
formEXdesktop.dll and threading.dll Byak@ Questions & Help Needed 5 08-13-2008 04:05 PM
Parallel Processing / Multi-Threading questions TWELVE Questions & Help Needed 7 04-29-2008 12:40 PM
Error on compile with Optimising TonyGprs Questions & Help Needed 4 01-27-2008 12:15 PM
The Hekkus Library doesn't work when used with the Optimized Compiler Louis Questions & Help Needed 5 12-28-2007 09:06 PM


All times are GMT. The time now is 10:09 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0