I want to know how erlang's VM preempts the running code and contexts the stack. How it can be done in a language such as c?
How does erlang implements preemptive scheduling with one OS thread?
724 Views Asked by BunnyDhaliwal At
2
There are 2 best solutions below
1
Tianpo Gao
On
All code of Erlang will compile to operation code of Erlang's VM. Erlang's VM execute Erlang's operation code by OS's threads which are created at startup of Erlang's VM.
Erlang's code run on Virtual CPUs which are controlled by Erlang's VM. And Erlang's VM consider IO as interrupt of Virtual CPUs. So Erlang's VM implements a machine and a scheduler like an OS. Because of operation code and non-blocking IO, we can implements preempts in Erlang's VM using C languange.
Related Questions in ERLANG
- Using gleam, cannot import 'gleam/otp/process'
- Zig Concurrency Vs Erlang Concurrency, is Zig less efficient than Erlang?
- Creaating a new Key Value dict from previous dict
- How to execute an exit function before closing rebar3 shell?
- rebar3 does not compile anything in `src` directory
- Ejabberd Migration from 23 to 24
- How to use compiled erlang modules in an elixir project?
- ejabberd_sql:handle_reconnect/2:491 odbc connection failed ejabberd
- Lisp Flavored Erlang: Can't find include lib include/ltest-macros.lfe
- Signing key for RabbitMQ
- Rabbitmq fails to start and getting Erlang eaacces error
- Erlang: binary_to_term explanation
- How to extend emqx clientInfo to get more fields during HTTP Authorization
- Transforming `erl_parse:abstract_form()` to `erl_syntax:syntaxTree()`
- Who is the sender of Erlang's trace messages and what can I assume based on it?
Related Questions in SCHEDULING
- Problem on CPU scheduling algorithms in OS
- Building a School Schedule Generator
- What are the motivating use-cases for each of Linux's SCHED_* scheduling algorithms?
- How to Schedule a Vertex AI Notebook Execution with Custom Environment Including Scripts and Config Files?
- Round Robin Implementation with Different Arrival Time
- Airflow: Find a DAG schedule Dataset URIs from DagBag
- Swiss Scheduling System for Ping-Pong league
- Only allow intervals to be produced on machines during shifts cp-sat or-tools
- what's the exact performance cost of context switch within the same thread? (memory access -> page fault -> memory access again)
- Scheduled method won't execute when I make a Spring bean to Application Scope
- Error while attempting to Implement Preemptive SJF in C
- How can we model the process scheduling mechanism in Linux using queueing theory models?
- OptaPlanner - use groupBy for avoidOvertime but only on the Resource creating the overtime
- Dynamic Flowfile Transfer Scheduling Using Quartz in NiFi Processors
- Setting up a Cron Job to Trigger on the Y-th Day Every Month, Handling Non-Existent Dates
Related Questions in PREEMPTIVE
- Non-preemptive authentication is not working with Jetty client library
- Linux Kernel thread preemption
- How to obfuscate const variable values using dotfuscator
- Do we still need runtime.Gosched() in go 1.19?
- Using Constraint Programming to model preemptive task with energy allocation over periods
- Azure Spot VM average up time
- Apache httpclient 4.5.13 preemptive authentication or not
- Creating a schedule for an example task set with non-preemptive Deadline Monotonic (fixed priority) scheduling
- gcp vm workers default gateway
- How to calculate the Starting time in a preemptive priority scheduling?
- Would preemptive scheduling affects speed of moving file?
- What kind of procedure is used to calculate the thread
- How to implement Priority Preemptive Scheduling (similar to interrupts) with threads in C++
- Shortest remaining time Job first scheduling algorithm clarification
- How to apply the algorithm of preemptive shortest job first in C
Related Questions in GREEN-THREADS
- Python Postgres Connections with Green Threads
- Kernel thread and user thread and their mechanism
- Confusion regarding the Blocking of "peer threads" when a user-level thread blocks
- How Kotlin coroutines will use Project Loom?
- Async and scheduling - how do libraries avoid blocking at the lowest level?
- At which point a goroutine can yield?
- Not able us Virtual Threads using Project Loom
- How to run multiple blocking loops simultaneously in Common Lisp. [Combining cl-async with queues in thread-pool]
- What data are shared between the green thread and the kernel level thread it is bound to?
- Is gevent pool wait_available thread safe
- How does erlang implements preemptive scheduling with one OS thread?
- Main thread context returning in a different hardware thread, undefined behaviour?
- Downside of green threads: host kernel thread blocks
- Green thread vs native thread vs daemon thread vs user thread
- I/O Blocking in Green threads
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The trick is that the Erlang runtime has control over the VM, so it can - entirely in userspace - keep track of how many VM instructions it's already executed (or, better yet, an estimate or representation of the actual physical computation required for those instructions - a.k.a. "reductions" in Erlang VM parlance) and - if that number exceeds some threshold - immediately swap around process pointers/structs/whatever and resume the execution loop.
Think of it something like this (in kind of a pseudo-C that may or may not actually be C, but I wouldn't know because I ain't a C programmer, but you asked how you'd go about it in C so I'll try my darndest):
This is obviously quite simplified (notably excluding/eliding a lot of important stuff like how VM instructions are implemented and how messages get passed), but hopefully it illustrates how (if I'm understanding right, at least) Erlang's preemptive scheduler and process model works on a basic level.