B4A Library Threading library

This library lets you run Basic4android Subs on separate threads to the main GUI thread. It also contains a Lock (semaphore) object that can be used for resource access arbitration and thread synchronisation.

Included is also an enhanced Exception object to give more information on any Exception caught. This can also rethrow those caught Exceptions and can create new Exceptions to throw.

EDIT :- Version 1.1 posted. See post #13 for details.
 

Attachments

  • Threading1.1.zip
    19.2 KB · Views: 7,226
Last edited:

stevel05

Expert
Licensed User
Longtime User
It is not possible to debug an app which contains a thread, (you can compile a module including a thread to a library and debug the rest of the app). You need to run the app in release mode.
 

kiki78

Active Member
Licensed User
Longtime User
It's normally not necessary for Activity, but try to pass Me as first parameter for Thread.Start.
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
The threading library misspells Initialize as Initialise

This is causing a warning in BJ4: Warning Variable 'whatever' is not Initialize. (warning #11)

Be nice if this was fixed
 

carlos7000

Well-Known Member
Licensed User
Longtime User
Hi.

I am trying to write an application that can distribute the work in several threads.

I have downloaded and tried the example

But I don't know how many threads I can create.

¿Do I create one for each processor?
¿Do I create a thread or each core?

¿How do I know how many threads I can create?

Thanks
 

mangojack

Well-Known Member
Licensed User
Longtime User
bug found (just now I know) The threading library misspells Initialize as Initialise

That has been mentioned a few times in this thread. Its the English UK spelling.


Will this be fixed, or...not?

Don't quote me ... but if its hasn't been changed over the past ten years , I think it unlikely. But who knows.
 

AscySoft

Active Member
Licensed User
Longtime User
I know this is a loooooong thread, and it's about the thread "as a library" Allow me not to ...
comparing apples to giraffes
:) I was forced lately to write a routine that will "unsubscribe from all topics" registered in firebase. As this routine only works in another thread (not in the main thread), I kindley sugest "a word" modification in threading library "Initialise>Initialize". I see always the warning for "Variable 'ThreadNameHere' was not initialized (warning #11), and after a while it's quite annoying. Thanks
 

AlainChipie

New Member
and the correct answer at "thread start doesn't work " is :) :

Thread1.Start(Me, "ThreadSub1",Null)

in release mode

thanks to all
 
Last edited:

rtek1000

Active Member
Licensed User
Longtime User
Bug found?
 

Attachments

  • bug.png
    bug.png
    77.1 KB · Views: 168

agraham

Expert
Licensed User
Longtime User
Bug found?
Check this link

We spell it 'Initialise' in the UK but the IDE looks for 'Initialize' :( It's been there forever and won't be changed.
 

rtek1000

Active Member
Licensed User
Longtime User
Check this link

We spell it 'Initialise' in the UK but the IDE looks for 'Initialize' :( It's been there forever and won't be changed.
Thank you for the explanation
 

rtek1000

Active Member
Licensed User
Longtime User
About Thread termination, is there any correct way to terminate the Thread?

In the example I found this sub routine:

B4X:
Sub Thread1_Ended(fail As Boolean, error As String) 'An error or Exception has occurred in the Thread

But even though the operations were performed correctly, apparently without errors, this subroutine Thread1_Ended returns a true value for Fail.

Thread1 Ended, fail: true error:

This indication is observed in B4J using this subroutine:
B4X:
Sub Thread1_Ended(fail As Boolean, error As String) 'An error or Exception has occurred in the Thread
    Log("Thread1 Ended, fail: " & fail & " error: " & error)
    If(error = "wrong number of arguments") Then
        Log("Try switching the compiler to 'Release' mode.")
    End If
End Sub


Even if the routine executed in the task is empty, this failure indication (fail: true from Thread1_Ended) still occurs:
B4X:
Sub File_Export2
   
End Sub
 

agraham

Expert
Licensed User
Longtime User
I'm afraid that the fail parameter is badly named. It is False if an exception occurred and error should hold the "Exception : " plus the exception type. If True the error is a blank string and the thread finished successfully. Forcibly stopping the thread by Thread.Interrupt will return False and error will be"Exception : lava.lang.InterruptedException"
 
Top