Skip to content

Detach current thread only at its exit #20

Open

Description

@MatteoArella

Actually we are calling AttachCurrentThread and DetachCurrentThread inside the logger_handler function (https://github.com/roc-project/roc-java/blob/master/roc_jni/src/main/cpp/logger.cpp);

As it has been discussed at #18 this can slow down performances.

A more efficient solution would involve detaching thread just before its exit, as it's described at https://developer.android.com/training/articles/perf-jni#threads:

you can use pthread_key_create() to define a destructor function that will be called before the thread exits, and call DetachCurrentThread() from there. (Use that key with pthread_setspecific() to store the JNIEnv in thread-local-storage).

Activity

  1. panwarab commented on Oct 1, 2020

    @panwarab

    let me take this up @MatteoArella @gavv
    what I need before working on this-

    • get started doc to do a dev setup
    • steps to repro the issue
  2. MatteoArella commented on Oct 2, 2020

    @MatteoArella
    MemberAuthor

    Great!

    A dev setup can be obtained running travis-ci jobs locally.

    Linux

    1. build libroc:
      scripts/travis/linux/before_install.sh
      scripts/travis/linux/install.sh
      
    2. build roc-java and run tests:
      ./gradlew build
      

    Android

    1. export some env variables for android environment configuration, for example:

      export JAVA_VERSION=8 
      export ANDROID_API=28
      export ANDROID_BUILD_TOOLS_VERSION=28.0.3
      export ANDROID_NDK_VERSION=21.1.6352462
      export ROC_BASE_DIR=/tmp/roc-build   # libroc prefix destination path
      
    2. build libroc for all android ABIs with:

      scripts/travis/android/install.sh
      
    3. build android subproject and run instrumented tests:

      scripts/travis/android/script.sh
      

    The step 3 will run a fresh docker container and a new AVD at each execution; if it's needed to only build and test android subproject (only after steps 1-2 are done) you can just run /bin/bash on rocstreaming/env-android:jdk$JAVA_VERSION docker image with:

    docker run -it --rm --privileged --env API=$ANDROID_API \
        --env BUILD_TOOLS_VERSION=$ANDROID_BUILD_TOOLS_VERSION \
        --env NDK_VERSION=$ANDROID_NDK_VERSION \
        --env ROC_BASE_DIR=$ROC_BASE_DIR \
        -v $PWD:$PWD -v $ROC_BASE_DIR:$ROC_BASE_DIR \
        -v android-sdk:/sdk -w $PWD \
            rocstreaming/env-android:jdk$JAVA_VERSION /bin/bash
    

    then create an AVD

    device --name "roc_device" --image "default" --api "${API}" create
    device --name "roc_device" start
    

    and finally build and test roc-android

    cd android
    ./gradlew build
    ./gradlew cAT --info --stacktrace
    

    Additional infos about our env-android docker image are available here.

  3. gavv commented on Dec 4, 2020

    @gavv
    Member

    @masterskipper Hi, do you still have plans on this issue?

  4. removed their assignment
    on Dec 5, 2020
  5. pinned this issue on Oct 12, 2024
  6. added theissue type on Feb 24, 2025
  7. unpinned this issue on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions