Android Question Encoding concurrent calls, blocking part of code, inheritance?

Darsiar

Member
Hello everyone!
Sorry, we didn’t quite understand how in B4A \ J
supported by:
1) parallel OS threads,
2) how to lock part of the code in the class:
loc
my code
end loc
3) how to inherit a new class from an already created one, or extend methods?

If this is very stupid, then we apologize again.
Schoolchildren and Minsk
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1, 2) You don't need to worry about it. Your code always run on the main thread. Libraries take care of managing slow tasks such as network communication with background threads.
3) There is in inheritance in B4X. You should instead use composition which means that a class holds an instance of the "base" class inside it.
 
Upvote 0

Darsiar

Member
And if you need to run background tasks on a timer? For example, you need several identical analyzers to process different scenarios at the same time.
How to launch a new routine?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can run as many timers as you like.

For example, you need several identical analyzers to process different scenarios at the same time.
The exact details are important. If for example you need to interact with a database then use the asynchronous methods. There are very rare cases where the processing is too slow.
 
Upvote 0

Darsiar

Member
Thank. But it is still not entirely clear how to lock a part of the code in order to avoid running several processes into one piece of code. In other languages, we used the lock operator for this - the end of the lock.
Like here?
 
Upvote 0

Darsiar

Member
Sorry for the stupidity, but this is not yet clear!
Suppose there is a class "A", which has a method of writing to the file "X".
We call Timer A, Record "X".
And at that moment, another call is reading or also writing "X" from the Web request. Ile is a process that works constantly because it was launched as the main supervisor.
What is tagda?
Usually an access conflict occurs.

Explanations: Let's say there is a certain library simulating the life of an animal (AI). She searches for something on the Internet, checks and cleans her memory, sorts and classifies various data received from different sources.
Another library crawls along these data in parallel, and makes its own decisions. For example, she can plan the actions of the first library or even the third, fourth.
At the same time, requests may come to the server, and it will do something with the "X" file.
Of course, it can be a database, but it is written here conditionally. Let this be the same file that is common to all.
And the access code to it is also common.
How to do without blocking?
thank
 
Upvote 0

Darsiar

Member
Many thanks!
This is already clearer.
But then, what should we do?
We have some excellent libraries of associative-dynamic AI already developed in VB.Net and C #, which we want to transfer (transcode) to B4X.

It uses the technology invented by us, "Management through a shared data memory." The essence of the idea is that at the same time how many independent processes are needed. Everyone does his own thing. They communicate through a trace left in shared memory.
They cannot work sequentially. These are completely different constantly active tasks.
How is this implemented on the B4X?

Can I introduce the system thread launch library?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Many tasks can run at the "same time". The exact details depend on the task nature. The more you can do asynchronously, the better.
Example with Sleep(0):
B4X:
Sub Test
    For i = 1 To 20
        CountToMillion("Counter " & i)
    Next
End Sub

Sub CountToMillion(CounterName As String)
    For i = 0 To 1000000
        If i Mod 100000 = 0 Then
            Log($"${CounterName}: ${i}"$)
            Sleep(0)
        End If
    Next
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…