Comments (11)
这儿不(只)在于FiberProc(fiber创建后第一次运行),在涉及到fiber::Mutex之类的场景,从pthread1加入wait-chain之后,可能立刻就会被pthread2从chain中弹出并准备执行,这时候需要某种同步机制达到「pthread2等待直到pthread1不再操作fiber_entity」,无论是spinlock,还是复用其他某个字段(比如fiber->state),最后对性能的影响应该都是类似的,相比之下spinlock更利于对整体代码的理解。
不过就性能而言,fiber调度的主要成本在于pthread2的唤醒,这儿多一个少一个atomic的操作应该实际上感知不到
from flare.
不排除我有什么地方记岔了,但是fiber的state应该只要能获取到scheduler_lock就可以访问,并不要求跟scheduling_group绑定
比如
SchedulingGroup::RemoteAcquireFiber
就是用来将fiber在scheduling group之间迁移的
噢好像,fiber单独拿出来使用也不能yield,要配合scheduling_group才能yield,也就不涉及waiting状态的改变。我的原意是指单独使用fiber的时候,去yield,fiber的状态没有变成waiting
from flare.
flare/flare/fiber/detail/fiber_entity.h
Lines 90 to 106 in 37be012
flare/flare/fiber/detail/fiber_entity.h
Lines 354 to 356 in 37be012
或许可以利用一下这个Argument
context
,fiber
切换过去再将caller fiber
的State
改变,状态改变的时候就不需要这把锁了?inline void FiberEntity::Resume() noexcept { SetCurrentFiberEntity(this); state = FiberState::Running; // Argument `context` set caller auto caller_ = jump_context(&caller->state_save_area, state_save_area, caller); // caller_ set nullptr when fiber return if (caller_) { static_cast<FiberEntity*>(caller_)->state = FiberState::Waiting; } ... } static void FiberProc(void* context) { auto caller = reinterpret_cast<FiberEntity*>(context); caller->state = FiberState::Waiting; //.... current_fiber->state = FiberState::Dead; GetMasterFiberEntity()->M_return([](){...}); } void FiberEntity::M_return(Function<void()>&& cb) noexcept { // set `resume_proc` .... SetCurrentFiberEntity(this); state = FiberState::Running; // set Argument `context` nullptr jump_context(&caller->state_save_area, state_save_area, nullptr); }
curren_fiber
的设置在yield
之前设置应该没问题吧, 如果有问题的话,context
就设置成这个吧
struct jump_context_data {
FiberEntity* self, *caller;
};
from flare.
不过现在这个写法,fiber的state就和schedulingGroup强绑定了,需要它才能去正确的得到fiber的state
from flare.
不排除我有什么地方记岔了,但是fiber的state应该只要能获取到scheduler_lock就可以访问,并不要求跟scheduling_group绑定
比如SchedulingGroup::RemoteAcquireFiber
就是用来将fiber在scheduling group之间迁移的
from flare.
// GetId()
?
this_fiber里这个返回debug_id不行么
from flare.
https://github.com/Tencent/flare/blob/master/flare/fiber/alternatives.h#L35
这个,用来不依赖__const__
那个hack的情况下获取当前线程id
from flare.
https://github.com/Tencent/flare/blob/master/flare/fiber/alternatives.h#L35
这个,用来不依赖
__const__
那个hack的情况下获取当前线程id
thread id也有errno这个问题吗
from flare.
//
GetId()
?
this_fiber里这个返回debug_id不行么
flare/flare/fiber/this_fiber.h
Line 48 in 37be012
flare/flare/fiber/detail/fiber_entity.h
Line 88 in 37be012
from flare.
thread id也有errno这个问题吗
有,其实用到thread-local storage都有可能有问题
this_fiber里这个返回debug_id不行么
这个id有需求可以返回,这个是fiber的id。但是async_test.cc那个测试里面测试的目的是「Dispatch方式运行的fiber会直接在caller的pthread里面运行」,所以比较的是threadid
from flare.
thread id也有errno这个问题吗
有,其实用到thread-local storage都有可能有问题
this_fiber里这个返回debug_id不行么
这个id有需求可以返回,这个是fiber的id。但是async_test.cc那个测试里面测试的目的是「Dispatch方式运行的fiber会直接在caller的pthread里面运行」,所以比较的是threadid
不是,这是另外一个话题了,我的意思是this_fiber.h
里怎么没有GetId
这个函数,实现就用fiber_entity
的debugging_fiber_id
不行吗,
flare/flare/fiber/this_fiber.h
Line 48 in 37be012
我看这里只是打了个问号
from flare.
Related Issues (20)
- Http header data structure HOT 13
- Rpc: Http parse HOT 5
- 针对K8s容器环境是否有需要注意的优化配置呢 HOT 2
- clang-format HOT 15
- update blade HOT 9
- logging HOT 11
- if have any plan to support bazel HOT 1
- bazel build ... 失败 HOT 6
- 请问有合适的源码阅读顺序吗 HOT 5
- 对GetFreeCount的取值比较困惑 HOT 5
- Does the server example in the flare example support 1 thread start? HOT 4
- clang-17 asan/tsan fiber coredump
- 关于Function类的疑问 HOT 2
- 问一个非常诡异的用例 HOT 10
- About unboxed_type_t HOT 2
- coredump when http overloaded HOT 2
- Timer HOT 6
- 为什么侵入式的链表采用的是组合而不是继承? HOT 5
- 使用`getaddrinfo`会不会更好一点 HOT 6
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 flare.