Android Question Threading... again

advansis

Active Member
Licensed User
Longtime User
Hi guys,
I think I really need splitting some methods in different threads upon different core-processors (I have a 8 core device)...
I'm building a light controller and I need a fast way to do several calculations in parallel.
For those who know, I'm speaking of "cue lists" and "effects", for those who don't, imagine you have several (>100) lamps and need to fade their brightness value from X1-value to X2-value,
each lamp with its own X1, X2 and time values...
This operation can be performed by one processor. Another processor can send these values through a serial port or WiFi. The main thread controls the user interface... And so on.
How can I achieve this? I tried the Agraham's Threading Library, but does not run in debug mode...
I've tried this extension, based on java's threads, but I don't know if it is really correct:
Java:
#if JAVA
public Thread bw;

public class backworker extends Thread {
    public int looptime=100;
    
    public backworker(int ms) {looptime=ms;}
    @Override
    public void run() {
        Exception lastex=null;
        try{
            boolean running=true;
            while (running) {
                Thread.sleep(looptime);
                ba.raiseEvent(null,"bk_run",null);
            }
            Object[] x3={true,null};
            ba.raiseEvent(null,"bk_ended",x3);
        }
        catch(Exception e){
            Object[] x2={false,e};
            ba.raiseEvent(null,"bk_ended",x2);
        }
    }
}

public void bw_init(int ms){
    bw=new backworker(ms);
}

public void bw_start(){
    if(bw!=null) bw.start();
}

public void bw_interrupt(){
    if(bw!=null) bw.interrupt();
}

public Thread.State bw_state(){
    if(bw==null) return Thread.State.NEW;
    return bw.getState();
}

#End If

Thanks in advance
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is not correct.

Another processor can send these values through a serial port or WiFi.
You don't need to do anything special except of using AsyncStreams.

I need a fast way to do several calculations in parallel
Which calculations? There are very few cases where you need to do anything special other than test performance in release mode.
 
Upvote 0

advansis

Active Member
Licensed User
Longtime User
It is not correct.


You don't need to do anything special except of using AsyncStreams.


Which calculations? There are very few cases where you need to do anything special other than test performance in release mode.

Erel, each channel (>100, but can be also 1000 or more) needs to be calculated (and send: I will use Lock objects to synchronize threads) 10/20 times each second. Some calculations include LOG/SIN functions, and values need to be bounded, scaled, bit-masked. I've tried, with some standard ResumableSub, but performance lacks...

I think using several threads on different processors (I have 8), can improve this...
 
Last edited:
Upvote 0

advansis

Active Member
Licensed User
Longtime User
Don't waste your time in building an unreliable solution. First step is to test it. My guess is that it will be fast enough.
Erel, I tried and wasted a lot of time (5 days or more) in speed improvement... it is not enough. Probably will use some external processors (esp32) and use Android as UI front-end... thanks anyway
 
Upvote 0
Top