Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips > Additional Libraries
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

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

Threading library version 2

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-31-2009, 04:51 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default Threading library version 2

As this is a significant rework of the original Threading library I have posted it in a new thread. The significant difference is that this version will operate in the IDE as well as when optimised compiled! That's right - you can now test threaded applications in the IDE - desktop and device! It seems to work fine in the IDE although obviously performance is not as good as when optimised compiled. I think it is pretty stable, I haven't experienced any crashes so far in testing so I think it is ready for the wider world.

The provision for locking resources has changed significantly. The previous RunLocked methods have been removed as they were inefficient to implement under the IDE. Instead two "proper" locking objects that are thin wrappers over two of the .NET locking objects are provided.

Library, help, source and demos in the zip. As before ThreadTestDevice.sbp needs my http://www.basic4ppc.com/forum/addit....html#post6582

EDIT :- Version 3.0 now posted for use with Basic4ppc v6.90 or later. See post #13 for details.
Attached Files
File Type: zip Threading2.0.zip (31.7 KB, 216 views)
File Type: zip Threading3.0.zip (31.8 KB, 179 views)
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 04-18-2010 at 05:00 PM. Reason: Erel: typo in title fixed.
Reply With Quote
  #2 (permalink)  
Old 08-31-2009, 06:34 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

This is amazing!
I didn't think that it is possible to add this support without some major modifications to the internal code.
Thank you once again.
Reply With Quote
  #3 (permalink)  
Old 08-31-2009, 06:55 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by Erel View Post
This is amazing!
Thanks Erel . I figured out that if the IDE code is re-entrant enough to cope with calling StartSub for Events and CallSub, which can occur in expressions, it was probably OK for Threading. Seems OK so far! It's a spin-off from trying to get a full Debug suite for the device IDE - specifically the Caller code.

EDIT: I really meant DoEvents not Events!
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 09-01-2009 at 08:22 AM.
Reply With Quote
  #4 (permalink)  
Old 01-04-2010, 10:25 AM
Byak@'s Avatar
Basic4ppc Veteran
 
Join Date: Jul 2008
Posts: 416
Send a message via ICQ to Byak@
Awards Showcase
Beta Tester 
Total Awards: 1
Default

and for this lib too :-[ (I'm say about adding a dispose method)
__________________
I'll Kill you, I'll Crash you, I'll never be yours!
--------------------------------------------------
Qtek s110; o2 XDA Flame; Nokia E63 red;
ASUS Eee PC 901 (Windows XP sp3) + TouchScreen;
Reply With Quote
  #5 (permalink)  
Old 01-04-2010, 10:45 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Same reply!
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #6 (permalink)  
Old 04-12-2010, 09:01 PM
Senior Member
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 154
Default

Hi Andrew,

first of all, thanks again for your great contribution..!

After some time went by i'm working on my piece of code where i embedded your threading lib a long time ago.It works great so far,currently having an issue with the thread is getting hung / crashing sometimes, but this is not subject of my post - not yet.

I intend to add more functions to my code, thus i need to check if a thread is still running.From the help file i found, that thread.running would be the property i have to check for, but unfortunately i could not figure out how to get this done.Likely, i'm facing the old problem : i do not think as much .NET as much it would be needed for this..*lol*

Basically, from my logic it would need to be done as following:

MyThread = CreateThread("MySub")
StartThread(MyThread)
If Thread.Running(MyThread) then ...

This is only an example, i know that the correct syntax is actually different from this.It is more PureBasic style, which i am using often for the pc as well.

This is a simplified version of my code in B4P:

AppStart
...
Thread.Start ( mySub)
...
AnotherSub
...
End Sub

MySub
..
do something
end Sub

AnotherSub
...
is the thread MySub still running ?
thread.running does not work, apparently the sub does not know about a thread object

EndSub

So how do i tell the thread.running what thread i am talking about...? Is it possible to use that property from a sub that was not the originator of the thread at all..?

I touch my B4P code first time after a quite long time i used other languages, so i apologize in advance if i overlooked something pretty easy...;-)

regards,

TWELVE
Reply With Quote
  #7 (permalink)  
Old 04-13-2010, 08:36 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Try Mythread.Running! Properties and methods need to be called on an object instance.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #8 (permalink)  
Old 04-13-2010, 06:55 PM
Senior Member
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 154
Default

Sorry...still not understood.Can you explain that more in detail..? How do i reference to a thread object i created in a different sub..? When did i a give name to my thread object...?

regards,

TWELVE
Reply With Quote
  #9 (permalink)  
Old 04-13-2010, 07:15 PM
Senior Member
 
Join Date: Apr 2008
Location: Duesseldorf, Germany
Posts: 154
Default

I got it to run the way i intended from the beginning:

if thread.running = true then

Initially i got an error message saying i had to create first this object.So i was in the belief the code is wrong, but apparently the property gives that error if the thread instance is not there (yet).

But, my intention was to test if the thread has terminated itself, which i'm waiting for before i gonna do something else.

1. how can i test if a thread is still existing ?

2. how can i differentiate between multiple threads ?

the thread.running has no reference to a particular thread, so could not address the thread i want.

The error behavior - btw - is a pain in the ass, because half of my code is code that tries to prevent uncaught .NET errors from happening.Usually one would expect a certain return value if an object does not exists, but in B4P it just throws an ugly .NET exception to the user.To be honest - i don't like that at all.


Edit: i found a "feature" in my code and just moved the Thread.New1(B4PObject(1)) into the app start section.Now the thread.running does not cause an error anymore.Maybe this solved another issue i was facing with the thread.



regards,

TWELVE

Last edited by TWELVE : 04-13-2010 at 07:33 PM.
Reply With Quote
  #10 (permalink)  
Old 04-13-2010, 08:11 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by TWELVE View Post
throws an ugly .NET exception to the user.To be honest - i don't like that at all.
I am afraid that is how .NET (and Java and to an extent C++) is designed to work. They throw execeptions instead of returning error codes. The intention is to better separate error handling code from normal path of execution code.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
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 Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Threading library for optimising compiler agraham Additional Libraries 46 08-31-2009 04:38 PM
Threading Mr_Gee Basic4ppc Wishlist 0 09-23-2008 07:57 PM
formEXdesktop.dll and threading.dll Byak@ Questions (Windows Mobile) 5 08-13-2008 03:05 PM
Version 6.01 Problem with SIP Features of Hardware Library Woinowski Bug Reports 4 01-08-2008 12:59 PM
New serial library - beta version Erel Announcements 13 08-02-2007 12:24 PM


All times are GMT. The time now is 06:55 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0