Git Product home page Git Product logo

androidcoroutine's Introduction

AndroidCoroutine

Related link: https://www.bilibili.com/video/BV1da411b7N8?spm_id_from=333.999.0.0

BackGround

  • Thread is controlled by jvm, we connot freely modify the state of thread, which cause the waste of computer resource.
  • It can improve performance of computer that if we use coroutine. Because we can use a new coroutine to execute other task when current coroutine is blocked.
  • The essece of performance improvement is that thread can execute continuously.
  • Kotlin coroutines are actually based on thread pool encapsulation. It encapsulates all coroutines with threads but does not have the ability to reduce CPU switching. A coroutine being suspended is actually a thread being suspended, and it does not achieve the ability to reuse the current thread to continue execution. Because kotlin is based on JVM, when a coroutine is suspended, it cannot continue to resume it because the suspended semaphore cannot be monitored. For example, if an IO interrupt occurs, or a network request or scheduling needs, he cannot obtain such a signal. Kotlin's delay() is actually implemented through the thread's sleep.

Feature

  • This is a custome library which implements the coroutine in C++.
  • Limited by jvm, this lib cannot support multiple suspend points .
  • When we compare this with kotlin coroutine library, we find that kotlin lib just is the same as a thread pool, limited by jvm, it can only bind one coroutine with one thread.

ToDo

  • Use kotlin suspend to solve callback syntax problems.
  • Suspension point implementation at the JVM layer statement level.
  • Using C semaphores to monitor IO interrupts and resume execution.

External Link

  • coroutine C++20 lib: It only provide some basic implementations of coroutine.
  • setjmp.h setjmp()/longjmp() C Lib
  • ucontext-cloudwu: It embeds the assembly through C, stores the current call stack into the register through assembly scheduling, and then switches to the next call stack for execution. It only implements the cpu architecture of x86 and x64, excluding the arm architecture of the mobile terminal.
  • Libco-Tecent: It's implementation refers to ucontext, and it only support x86.

androidcoroutine's People

Contributors

kymjs avatar rocksnake avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.