Comments (9)
Any thoughts on the proposal here? I'm also interested in avoiding long-running work on one thread preventing a fiber from being scheduled on another. I think deferring to the scheduling algorithm, but having default implementations to keep existing algorithms still correct ought to be possible?
from fiber.
- the user is responsible for the scheduling-algorithm, of course an note should be added in the documentation
- fibers != threads, e.g. a fiber will always belong to a thread (tuns in the context of a thread)
- fiber can be migrated/moved between threads
std::thread, which defines a crash if any thread remains after main() exit
does not produce crashes:
int main() { std::thread([](){ std::cout << std::this_thread::get_id() << ": sleeping" << std::endl; std::this_thread::sleep_for( std::chrono::seconds( 1) ); }).detach(); std::this_thread::sleep_for( std::chrono::seconds( 1) ); std::cout << "main() returns" << std::endl; return 0; }
- only detached fibers remain in the scheduler while terminating/returning from main()
- of course std::terminate() could be called if fibers are pending while entering ~scheduler()
- what should be the benfit of mving timers, remote-ready-queue to algorithm?
from fiber.
- I mean, algorithm should be bound to main fiber stack, since it's the entrypoint and the exit point
Thus, it shouldn't be touched after main fiber is terminated
Details: I'm passing a non-static shared scheduler data to algorithm. shared_work is static based so it's not affected. - Remote ready queue is useless if you're doing a multi-threaded algorithm (locking is required regardless local or remote).
- Sleep queue should be shared between threads so we don't need to wait for scheduler kicking in the target thread
Consider the following case:
Thread A is running a long job and has something near to expire in the sleep queue
Thread B cannot pull that job in sleep queue because sleep2ready isn't executed until the A's long job pass control to scheduler
from fiber.
- remote-ready-queue is not useless - how would you notify the scheduler of thread A that its fiber f1 is ready (was waiting on condition_variable) from thread B (signals condition_variable).
- sleep-queue should only be modified by its owning scheduler - otherwise it would require synchronization
from fiber.
- remote-ready-queue isn't needed for threaded applications using things like shared_work; they do the synchronization itself on ready-queue. It doesn't necessarily need a dedicated queue.
- allow the algorithm to synchronize itself; locking isn't so expensive since atomic based queues exist, we need the maximum flexibility on work-stealing instead
from fiber.
The concept:
- Attached attribute 'timer' for an asio timer, used for scheduling sleeping (asio manages sleep queue on itself)
- Shared ready queue
- Instead of set_ready, use a special mutex-unlocked version in the asio callbacks
The pseudocode:
void set_ready(ctx) // Previously awakened
{
lock_guard lk;
que.push(ctx);
}
void set_ready_unlocked(ctx) // omitted
void set_remote_ready(ctx)
{
set_ready(ctx);
// It's useful for non work-sharing schedulers
}
void set_sleep(ctx)
{
ctx.attr['timer'].async_wait([&]{set_ready_unlocked(ctx);});
}
ctx* pick_next() // A different design, block until jobs are available
{
lock_guard lk;
while(que.empty()) {iosvc.run_one();iosvc.poll();}
return que.first();
}
// suspend and notify are removed in favor of internal sleep impl
from fiber.
I'm sorry - I'm too busy ...
from fiber.
Has any more thought been put into this? I tend to agree that there needs to be a way to move items in the remote_ready queue to a scheduler that that can actually schedule it instead of waiting for the original scheduler to "wake up".
If some of the logic was moved to algorithm away from the scheduler the queues for sleep and remote_queue could be kept in a way that ready fibers could be scheduled without waiting for the original scheduler.
I don't think that "synchronization would be required" is a reason not to implement.
Would some change in this area help with ASIO integration? The idea being that we need to get a way from fibers being so tied to schedulers. If it did not matter which scheduler processed it, we would not be hamstrung by the fact that you cannot wake a particular ASIO thread if multiple threads are executing "run()".
Just my $.02, thoughts?
from fiber.
unfortunately not yet -at the moment I've too many other stuff on my desk
from fiber.
Related Issues (20)
- Boost.fiber incompatible with C++20 HOT 1
- Boost.Fiber header compile fails with GCC Compile option -Werror=conversion
- Maybe a semaphore should be added HOT 1
- segment fault when closed buffered_channel on destructor
- build failed with cxxflags -D BOOST_FIBERS_NO_ATOMICS (version 1.80.0)
- Warning/error about unreferenced parameter in context.cpp HOT 2
- std::aligned_storage raises deprecation warning with the latest gcc 13 and C++23 (to be released in about 1 month and a half) HOT 2
- Boost fiber's demo run error when open AddressSanitizer by use Visual Studio HOT 1
- Build script relies on third party to import Context before Fiber
- Weird behavior with custom `algorithm_with_properties<>`
- Memory leak exists when setting custom scheduler algorithm in use_scheduling_algorithm function? HOT 1
- fiber::sleepfor stop updating when system clock moves backwards
- Launching fiber on a different thread HOT 3
- Could not link fiber 1.84.0 as shared library on Windows 10 HOT 4
- Mixing `fiber::mutex` and normal threads HOT 1
- Modular Boost C++ Libraries Request
- use it in qt
- Weird infinite loop when cv.notify_all() HOT 3
- no way to calculate hash of `fiber::id`
- Explicit context switch of fibers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fiber.