green threads are fucking retarded
绿线太他妈的迟钝了
绿线太他妈的迟钝了
what about this thread
这个线程怎么样
async await backed by a threadpool is better than goroutine trash
由线程池支持的 async wait 比 goroutine 垃圾更好
>>109555114
> this isn't about greentext threads
> 这与绿色文本线程无关
>>109555114
>>109555129
ok, no shit? it's a trade-off.
好吧,没啥事吧?这是一个权衡。
greenthreads mimick the simplistic execution model everyone can understand.
greenthreads 模仿每个人都能理解的简单执行模型。
>>109555611
>greenthreads mimick the simplistic execution model
>greenthreads 模仿简单的执行模型
thats a bad thing
那是一件坏事
>>109557151
it is today, but it was a necessary pain in the past.
今天是这样,但过去却是必要的痛苦。
the fist jvms didn't support os level threads
第一个 jvm 不支持操作系统级线程
and you had to rely on threads for anything that required preemptive multitasking.
并且您必须依赖线程来完成任何需要抢占式多任务处理的事情。
sure coroutines (cooperative multitasking) and async/await (to some extent) deliver better performances, but they're complex to implement and require your language to be built from the grounds up to properly support them.
某些协程(协作多任务)和异步/等待(在某种程度上)可以提供更好的性能,但它们实现起来很复杂,并且需要从头开始构建语言才能正确支持它们。
that's where green thread fit imo.
在我看来,这就是绿线适合的地方。
>>109555127
This is a blue board but I like the look of Yotsuba A better.
这是一块蓝色的板,但我更喜欢 Yotsuba A 的外观。
>>109555114
link?
>>109555114
>but it is still a complete execution context. At a minimum, it must preserve register state, a call stack, and metadata used by the runtime scheduler
>但它仍然是一个完整的执行上下文。至少,它必须保留运行时调度程序使用的寄存器状态、调用堆栈和元数据
a goroutine also needs all these things
Goroutine 也需要所有这些东西
>>109557280
You know what else fits?
你知道还有什么适合吗?
My dick, inside you
我的鸡巴,在你体内
>>109555129
hehehe.. i almost though that is some non-retard who made a proper statement, then, saw this..
呵呵..我几乎以为那是一个做出了适当声明的非弱智,然后,看到了这个..
nope, you're retarded. it is the same threading model, OS threads just an extension of the "green" threads and parallelism in general is a subset of concurrency/asynchronicity.
不,你是弱智。它是相同的线程模型,操作系统线程只是“绿色”线程的扩展,而并行性通常是并发/异步性的子集。
also these retarded black on white screencaps. write white on black next time
还有这些延迟的白底黑屏。下次黑底白字
>>109555129
>async await backed by a threadpool is better than goroutine trash
> 由线程池支持的异步等待比 goroutine 垃圾更好
they are practically the same thing
它们实际上是同一件事
in both cases you have user space threads, that can be implemented using either cooperative yielding or preemption under the hood but that are preemptive as far the user is concerned, that do I/O in a way that doesn't block the kernel thread
在这两种情况下,您都有用户空间线程,可以使用协作让出或抢占来实现,但就用户而言,它们是抢占式的,以不阻塞内核线程的方式执行 I/O
the main difference is that goroutines block from the POV of the user and implicitly wait the results, while with async await the user has to await explicitly
主要区别在于 goroutine 会阻止用户的 POV 并隐式等待结果,而使用 async wait 时用户必须显式等待
>>109558409
learn to read
识字
finally people are waking up to the retardation of green threads.
人们终于意识到绿线的延迟作用。
>>109558957
a goroutine also needs all these things, use your brain
Goroutine 也需要所有这些东西,开动你的大脑
>>109559097
you still can't read. he is describing goroutines you dumb fuck. async doesn't need any of these
你还是看不懂。他正在描述 goroutine 你这个笨蛋。 async 不需要这些
>>109555114
Always has been.
从来就是这样。
State machines have always been superior to green threads.
状态机始终优于绿色线程。
>But muh function coloring!!!!
>但是多功能着色!!!
Literally not a problem in the real world. Especially not with languages that allow you to block while you wait.
从字面上看,这在现实世界中不是问题。尤其是那些允许你在等待时阻塞的语言。
>>109558978
One thing I'm really happy about is that nowadays, developers have learned to appreciate good type systems. 10+ years ago everyone was raving about the "flexibility" of languages where variables and parameters could just be any type at runtime and freely switch between them.
我真正高兴的一件事是,如今,开发人员已经学会欣赏好的类型系统。十多年前,每个人都对语言的“灵活性”赞不绝口,其中变量和参数在运行时可以是任何类型,并且可以在它们之间自由切换。
I guess that since them, developers had to maintain applications written in these languages by other developers and learned that knowing what kinds of parameters functions take and having a compile time warning is worth it.
我想从那时起,开发人员就必须维护其他开发人员用这些语言编写的应用程序,并了解到了解函数采用什么类型的参数并发出编译时警告是值得的。
Just a shame that the biggest winner was TypeScript so modern applications are slow as shit.
遗憾的是,最大的赢家是 TypeScript,所以现代应用程序慢得要命。
>>109558978
dumb ass blog post
愚蠢的博客文章
he mixes together green threads, goroutines and fibers. They are different.
他将绿色线程、goroutines 和 Fiber 混合在一起。他们是不同的。
when comparing async-await to green theads, the async attributes and function signature is a secondary concern. The main concern is how well does each concurrency primitve compose with concurrent code and with regular synchronous code.
将 async-await 与 green thead 进行比较时,异步属性和函数签名是次要问题。主要关注的是每个并发原语与并发代码和常规同步代码的组合效果如何。
>Similarly, its common to see code in languages like go that doesn’t use concurrency where it could because it’s not obvious that the underlying calls perform IO.
>类似地,在像 go 这样的语言中,经常会看到代码在可以使用并发的地方不使用并发,因为底层调用执行 IO 并不明显。
Ok, in other words it's a user issue.
好吧,换句话说,这是一个用户问题。
>One of the key advantages of async-await is that it gives you the future to combine with other futures.
> async-await 的主要优点之一是它为您提供了与其他 future 结合的 future。
A future is merely a type system thing and doesn't intrisically gives you automatically an I/O multiplexing although with languages will generally have it. At the same time, languages without async and futures can have I/O mulitplexing. Go has it for example.
future 只是一个类型系统的东西,本质上并不会自动为您提供 I/O 多路复用,尽管语言通常会有它。同时,没有 async 和 future 的语言也可以进行 I/O 复用。例如,Go 就有它。
>This allows you to turn your sequential code into more of a dependency map going from blocking location to blocking location minimizing the number of non-concurrency tasks with Promise.all (or Future::join or asyncio.gather depending on your language).
>这允许您将顺序代码变成更多的依赖关系图,从阻塞位置到阻塞位置,最大限度地减少使用 Promise.all(或 Future::join 或 asyncio.gather,具体取决于您的语言)的非并发任务的数量。
Promise.any is the same thing as a bare I/O multiplexing call and Promise.all is trivial to implement.
Promise.any 与裸 I/O 多路复用调用相同,并且 Promise.all 实现起来很简单。
>While languages like go have similar mechanisms, they do not match the convenience of being able to await a list of futures, and for an arbitrary list you can be forced to build a giant pile of channels to try and handle successes vs failures or deal with trying to build your own result types.
>虽然像 go 这样的语言具有类似的机制,但它们不符合能够等待 future 列表的便利性,并且对于任意列表,您可能被迫构建大量通道来尝试处理成功与失败或尝试构建自己的结果类型。
This is one of those cases where the dude pretends that function definitions don't exist. They do. Once written, the "problem" cease to exist.
这是该家伙假装函数定义不存在的情况之一。他们确实这么做了。一旦写出来,“问题”就不复存在了。
>>109559602
>Go you don’t have the flexibility of promises to either block on them or not, you always block
>你没有灵活的承诺来阻止或不阻止它们,你总是阻止
That's true but if you don't have a polling primitive, not blocking won't give you any more flexibility concurrency wise. Creating futures in a loop and await them all is not that much different than creating goroutines in a loop and I/O multiplexing wait them.
确实如此,但如果您没有轮询原语,则不阻塞不会给您带来更多的并发灵活性。在循环中创建 future 并等待它们与在循环中创建 goroutine 并 I/O 多路复用等待它们没有太大区别。
>sequential code isn’t necessarily that useful, what we actually want is a way to map dependencies between lines of code
>顺序代码不一定有用,我们真正想要的是一种映射代码行之间依赖关系的方法
sequentical code CAN be useful and as for the dependence thing he's is talking about, either you have non-blocking I/O and you can do a multiplexed I/O wait later then code using the filehandles, either you have something like gorouintes that blocks but you still have the goroutines references as handles that you can multiplex wait for.
顺序代码可能很有用,至于他所说的依赖关系,要么你有非阻塞 I/O,你可以稍后进行多路复用 I/O 等待,然后使用文件句柄进行编码,要么你有像 gorouintes 这样的东西会阻塞,但你仍然有 goroutine 引用作为可以多路复用等待的句柄。
>Function colors as a way of labeling functions in the type system
>函数颜色作为类型系统中标记函数的一种方式
>Async-Await is only one type of labeling we can do in this space,
>Async-Await 只是我们在这个领域可以做的一种标签类型,
Function coloring is bad and we could label the promise value itself, no need to label the entire function which gives no benefit.
函数着色很糟糕,我们可以标记承诺值本身,而不需要标记整个函数,这不会带来任何好处。
>So if we consider the primary goal of async-await based concurrency to be marking functions that don’t block,
>因此,如果我们认为基于异步等待的并发的主要目标是标记不阻塞的函数,
How is that a goal? That's a negative and effect systems suck.
这怎么算是一个目标呢?这是一个负面效应,系统很糟糕。
>Similarly in high performance computing it can be helpful to know if code branches or loops, you could build a language where you cannot use for (or recursion) or if unless you explicitly mark the function
>类似地,在高性能计算中,了解代码是否分支或循环会很有帮助,您可以构建一种不能使用 for (或递归)或 if 的语言,除非您明确标记该函数
mental retardation
智力低下
>>109559237
>he is describing goroutines you dumb fuck
>他正在描述 goroutine 你这个笨蛋
I'm aware retard. He said that green threads has
我知道迟钝。他说,绿线有
>a complete execution context. At a minimum, it must preserve register state, a call stack, and metadata used by the runtime scheduler
> 完整的执行上下文。至少,它必须保留运行时调度程序使用的寄存器状态、调用堆栈和元数据
I'm just saying that goroutines also needs all of those. What part of this is wrong? What part of this is hard to understand? Stop replying for saying nothing of value you inbred.
我只是说 goroutine 也需要所有这些。这哪一部分是错误的?这其中哪一部分难以理解?不要再回复说你近亲繁殖的任何有价值的内容。
>async doesn't need any of these
>async 不需要这些
And? async wasn't mentioned anywhere in the text in the post I replied to you massive inbred faggot
和?我回复你的帖子中的任何地方都没有提到异步
>>109559237
>async doesn't need any of these
>async 不需要这些
I concur. I/O multiplexing doesn't require many little stacks in the heap for the goroutine but goroutines can do more than I/O multiplexing, they can be also used to do do run code in parallel.
我同意。 I/O 多路复用不需要 goroutine 在堆中放置很多小堆栈,但 goroutine 可以做的不仅仅是 I/O 多路复用,它们还可以用于并行运行代码。
Howver if you do need to process in parallel the results of those IO calls, with goroutines you don't have to use a work queue and a thread pool because the goroutines are already scheduled but you would need that with async.
然而,如果您确实需要并行处理这些 IO 调用的结果,则使用 goroutines 就不必使用工作队列和线程池,因为 goroutine 已经被调度,但您需要使用异步。
stackful coroutines are better
堆栈协程更好
enjoy your colored functions
享受你的彩色功能
Can someone explain like I'm a nigger
有人可以像我是黑鬼一样解释一下吗
>async
>stackful coroutines
>堆栈协程
>functions of color
>色彩的功能
>promises
>green threads
>绿线
Reject modernity, embrace tradition.
拒绝现代,拥抱传统。
Callbacks and event loops allow you to avoid all this nonsense.
回调和事件循环可以让您避免所有这些废话。
total async death
完全异步死亡
>>109559809
there's literally nothing wrong with colored functions you crybaby faggots. it's just a marker that the function doesn't block the thread the same way you could introduce other markers like alloc to mark functions that allocate and then only functions that also have an alloc marker could call that function etc... it's a good thing
彩色函数实际上没有任何问题,你们这些爱哭鬼。它只是一个标记,表明该函数不会阻塞线程,就像您可以引入其他标记(例如 alloc)来标记分配的函数一样,然后只有也具有 alloc 标记的函数才能调用该函数等...这是一件好事
>>109555114
Why? Please be concrete. Not ITS BAD IT"S JUST IS OK
为什么?请具体说明。不是很糟糕,只是还可以
>>109555129
nobody uses intel cet
没有人使用Intel CET
>>109562169
Do any consumer-grade CPUs even have it?
消费级 CPU 是否具备此功能?
I remember the C# team experimented with switching to green threads from async when green threads were the rage and they concluded that it's fucking trash and wrote a blogpost about it.
我记得当绿色线程流行时,C# 团队尝试从异步切换到绿色线程,他们得出的结论是这太垃圾了,并写了一篇关于它的博文。
remember that the guy arguing for async await writes C# webapps which don't follow the rules and just block anyway because async/await makes for a terrible programming model (well yes, that's the point of having green threads)
请记住,争论 async wait 的人编写的 C# Web 应用程序不遵循规则,并且无论如何都会阻塞,因为 async/await 造成了一个糟糕的编程模型(是的,这就是拥有绿色线程的意义)
>>109562623
the conclusion was that it's too hard / confusing to support both, so they are doubling down on async / await and trying to make that less trash
结论是,同时支持两者太难/令人困惑,因此他们在 async/await 上加倍努力,并试图减少垃圾
>>109562623
>The downside of async C# code is in that developers must decide which methods need to be async. It is not viable to simply make all methods in the program async. Async methods have lower performance, limitations on the type of operations that they can perform and async methods can only be called from other async methods . It makes the programming model complicated. What color is your function is a great description of this problem.
>异步 C# 代码的缺点是开发人员必须决定哪些方法需要异步。简单地使程序中的所有方法都异步是不可行的。异步方法的性能较低,它们可以执行的操作类型受到限制,并且只能从其他异步方法调用异步方法。它使编程模型变得复杂。你的函数是什么颜色很好地描述了这个问题。
>The key benefit of green threads is that it makes function colors disappear and simplifies the programming model. The green threads should be cheap enough to allow all code to be written as synchronous, without giving up on scalability and performance. Green threads have been proven to be a viable model in other programming environments.
>绿色线程的主要好处是它使函数颜色消失并简化了编程模型。绿色线程应该足够便宜,以允许所有代码同步编写,而不放弃可扩展性和性能。绿色线程已被证明是其他编程环境中的可行模型。
>We have chosen to place the green threads experiment on hold and instead keep improving the existing (async/await) model for developing asynchronous code in .NET. This decision is primarily due to concerns about introducing a new programming model.
>我们选择暂停绿色线程实验,而是继续改进现有的(异步/等待)模型,以在 .NET 中开发异步代码。这一决定主要是出于对引入新编程模型的担忧。
https://github.com/dotnet/runtimelab/issues/2398
in other words: what we have is trash, other languages have something better, we are in too deep now and have to live with the trash we got
换句话说:我们拥有的是垃圾,其他语言有更好的东西,我们现在陷得太深了,不得不忍受我们得到的垃圾
>>109562865
explicit yielding is better than implicit, as with almost anything when writing code. They would want to have green threads because c# is popular enough for them to want it to cater to lowest common denominator which are hordes of pajeets spewing out garbage code. They don't want the programmer to have to think what he's doing, because he would have to have a slightest idea how shit works. The same reason why python and js are the most popular languages. What? Defining types? A type system? What even is a memory you're talking about? I don't know, I just copy paste stuff from react tutorial (claude copies it for me).
显式生成比隐式生成更好,就像编写代码时的几乎任何事情一样。他们希望拥有绿色线程,因为 c# 足够流行,他们希望它能够满足最低公分母,即大量喷出垃圾代码的 pajeets。他们不希望程序员必须思考他在做什么,因为他必须知道一点点狗屎是如何工作的。 python 和 js 是最流行语言的原因是一样的。什么?定义类型?类型系统?你所说的记忆到底是什么?我不知道,我只是从反应教程中复制粘贴内容(克劳德为我复制)。
>>109563607
green threads are a high level construct, just like garbage collection. you exchange some efficiency and control for robustness in large programs. async/await is a low level construct that gives the programmer more control but also more busywork that doesn't have anything to do with the problem they are trying to solve. rust has async/await because it's a low level language and control is paramount. js has it because they have no other choice because the languahe is single threaded. the c# devs simply got it wrong and can't change it now, they admitted it themselves. this is not a hill to die on anon, it's trash and arguing otherwise is like a c programmer arguing that header files are amazing technology
绿色线程是一个高级构造,就像垃圾收集一样。您可以用一些效率和控制来换取大型程序的鲁棒性。 async/await 是一个低级构造,它为程序员提供了更多控制权,但也提供了更多与他们试图解决的问题无关的繁忙工作。 rust 具有 async/await,因为它是一种低级语言,并且控制至关重要。 Node.js 拥有它是因为他们别无选择,因为语言是单线程的。 C# 开发人员只是弄错了,现在无法更改,他们自己也承认了。这不是马上就死掉的一座山,它是垃圾,争论否则就像一个 C 程序员争论头文件是令人惊叹的技术
>>109555114
>green threads are fucking retarded
>绿色线程他妈的迟钝
There is a reason why Rust ditched them for stackless, polling async-await.
Rust 放弃它们而采用无堆栈、轮询异步等待是有原因的。
>>109559717
You can have both. You can have multithreaded async without stacks.
你可以两者兼得。您可以在没有堆栈的情况下进行多线程异步。
>>109564233
It's a real stretch to call the tooling around async/await low level in C#. Working with threads and mutexes sure that's low level but you really don't burn that much mental energy on the model C# went with.
在 C# 中调用 async/await 低级别的工具确实是一个很大的挑战。使用线程和互斥体肯定是低水平的,但你确实不会在 C# 所使用的模型上消耗太多的精神能量。
My biggest pet peeves with concurrency in C# atm is the conventions around passing around cancellationtokens and how really clunky it is to go from non coloured to coloured functions.
我对 C# atm 中的并发性最大的不满是围绕传递取消令牌的约定,以及从非彩色函数到彩色函数的笨重程度。
I've been writing Go since 2012 as well and I wouldn't say a non coloured language is all that big a perk to have.
我从 2012 年起就开始编写 Go,我不认为非有色人种语言有那么大的好处。
Hopefully we get a full set of tooling for async await in C++ in 29.
希望我们能在 29 中获得一整套 C++ 异步等待工具。
>>109562865
C# can call async functions from non async just fine. You just have to either ignore the result or poll or block waiting for the result.
C# 可以很好地从非异步调用异步函数。您只需忽略结果或轮询或阻止等待结果。
In languages with green threads, it's the same. Calling a blocking operation simply blocks the thread. You have to explicitly say "run this on a green thread" and you still have to somehow wait for or poll the readyness state of the result if the calling thread cares to receive a result without blocking itself.
在具有绿色线程的语言中,情况是相同的。调用阻塞操作只会阻塞线程。您必须明确地说“在绿色线程上运行它”,并且如果调用线程希望在不阻塞自身的情况下接收结果,您仍然必须以某种方式等待或轮询结果的就绪状态。
With explicit types - Task<Result> -(the "evil function color, aka, typing) it becomes obvious what is an IO function you most likely want to not block on.
使用显式类型 - Task<Result> -(“邪恶函数颜色,又名打字),很明显什么是您最可能不希望阻止的 IO 函数。
go routines are so much nicer than dealing with await tranny garbage
go 例程比处理等待变性垃圾要好得多
>>109564233
so what programming language should we use instead? java?
那么我们应该使用什么编程语言呢? java?
>c++
bloated that takes 5 years just to not make the 200 most common default mistakes
臃肿需要 5 年时间才能不犯 200 个最常见的默认错误
>c
bloated that takes 5 years just to not make the 200 most common default mistakes
臃肿需要 5 年时间才能不犯 200 个最常见的默认错误
there literally isnt anything else to use besides c# and java and java doesnt allow you memory control
除了c#和java之外,实际上没有其他东西可以使用,而java不允许你进行内存控制
>>109564305
Idk what you mean chief, you need to be more explicit.
楼主,我明白你的意思,你需要说得更明确一些。
>>109564359
>C# can call async functions from non async just fine
>C# 可以从非异步调用异步函数就好了
here you have eric lippert telling you that this is bullshit and what you are doing rrsults in deadlocks : https://stackoverflow.com/a/45059862
>You do not correctly block on async code. Blocking is wrong. Asking what the right way is to do the wrong thing is a non-starter.
>您没有正确阻止异步代码。封锁是错误的。询问做错事的正确方法是行不通的。
putting your fingers in your ears and ignoring the problem is not a solution. you are doing it because you don't want to deal with async/await. yes, that's the point of green threads where you can block and don't get deadlocks
把手指放在耳朵里并忽视问题并不是解决问题的办法。你这样做是因为你不想处理异步/等待。是的,这就是绿色线程的要点,您可以在其中阻塞并且不会出现死锁
>>109564343
the model is not hard to understand but it is annoying to deal with, so much that one anon in this thread is ignoring how it works and blocks anyway, risking deadlocks. it is also annoying to structure your program around memory lifetimes, you'd much rather pay for gc than deal with the rust borrow checker for example. same story here
该模型并不难理解,但处理起来很烦人,以至于该线程中的一个人忽略了它的工作原理并无论如何都会阻塞,从而冒着死锁的风险。围绕内存生命周期构建程序也很烦人,例如,您宁愿为 gc 付费也不愿处理 rust 借用检查器。同样的故事在这里
>>109564414
c# is a fine language otherwise, lots of features that java and go don't have. but pretending that async/await is not a mistake misplaced in a high level language is disingenous. it's allowed to have nuanced opinions, just because one aspect is retarded doesn't invalidate the rest. i prefer java because it's not as feature bloated, but either is fine
c# 是一种很好的语言,否则有很多 java 和 go 没有的功能。但是假装 async/await 不是高级语言中的错误是不诚实的。允许有细微差别的意见,仅仅因为某一方面存在缺陷,并不意味着其他方面就无效。我更喜欢java,因为它的功能不那么臃肿,但两者都很好
>>109559873
threads r hard
线程 r 硬
>>109559641
>a goroutine, for EXAMPLE (of a green thread)
> 例如(绿色线程的)goroutine
back2school
>>109559873
green threads are like taking a slice of bread and spreading the ready-made pb&j on it
绿线就像拿一片面包,把现成的pb&j铺在上面
async state machines are like spreading and scraping the ready-made pb&j on the same slice of bread
异步状态机就像在同一片面包上涂抹和刮擦现成的 pb&j
>>109566625
That stackoverflow answer is retarded. "Blocking on async code is wrong because... the second async operation will be scheduled to this thread" doesn't even make sense - if the current thread is running user code, and it chooses to block on the async operation, the thread isn't returned to the managed threadpool, so why would the second async operation be scheduled to run on it? Like if his argument is "the Task you're trying to block on may have synchronous continuations or have been scheduled with an explicit TaskScheduler that requires your thread to execute" - like a WinForms app or something, where the SynchronizationContext is used to ensure async callbacks execute on the UI thread - then sure, you'll deadlock. But just... don't fucking do that? Like, what, should I never use a synchronization primitive like a mutex because maybe I can write stupid code that deadlocks?
stackoverflow 的答案是迟钝的。 “阻塞异步代码是错误的,因为......第二个异步操作将被调度到该线程”甚至没有意义 - 如果当前线程正在运行用户代码,并且它选择阻塞异步操作,则该线程不会返回到托管线程池,那么为什么要调度第二个异步操作在其上运行呢?就像如果他的论点是“你试图阻止的任务可能有同步延续,或者已经使用需要你的线程执行的显式 TaskScheduler 进行了调度” - 比如 WinForms 应用程序或其他东西,其中 SynchronizationContext 用于确保异步回调在 UI 线程上执行 - 那么当然,你会死锁。但只是...他妈的不要这样做吗?就像,什么,我不应该使用像互斥体这样的同步原语,因为也许我可以编写导致死锁的愚蠢代码?
If I have a synchronous method that wants to block on an asynchronous operation, it's unfortunate that the best solution is to tie up a thread owned by the managed pool - because now my operation is consuming two threads, once to do the asynchronous work and the other to wait for the work to complete - but to say "blocking is wrong" is silly. And if you know you don't need to restore the thread state when resuming from the operation, you could always call `.GetAwaiter().GetResult()` to avoid the extra thread.
如果我有一个想要阻塞异步操作的同步方法,那么不幸的是,最好的解决方案是绑定托管池拥有的线程 - 因为现在我的操作正在消耗两个线程,一个执行异步工作,另一个等待工作完成 - 但说“阻塞是错误的”是愚蠢的。如果您知道从操作恢复时不需要恢复线程状态,则可以随时调用 `.GetAwaiter().GetResult()` 来避免额外的线程。
>>109566888
except that a goroutine is not a green thread
除了 goroutine 不是绿色线程之外
>>109567165
the only distinction that you can make is that green threads were historically supported by a single real thread but that was never a necessity of green threads so goroutines and green threads are the same
唯一可以做的区别是,绿色线程在历史上是由单个真实线程支持的,但这从来都不是绿色线程的必要条件,因此 goroutine 和绿色线程是相同的
>>109567215
green threads block the kernel thread if they make synchronous calls, goroutines block from the POV of the user but since they used a non-blocking or asynchronous call under the hood they don't block the kernel thread
绿色线程如果进行同步调用,则会阻塞内核线程,goroutine 会从用户的 POV 处阻塞,但由于它们在幕后使用非阻塞或异步调用,因此不会阻塞内核线程
goroutines were originally and for a long time non-preemptive, while green thread are preemptive and even interruptible, directly without using an explicit channel
goroutine 最初并且在很长一段时间内是非抢占式的,而绿色线程是抢占式的,甚至是可中断的,无需使用显式通道即可直接中断
>>109567279
>>109567279
>he needs LLM to understand
>他需要LLM才能理解
brainlet
>green threads didn't inherently block the kernel thread
>绿色线程本质上不会阻塞内核线程
I said for synchronous calls you stupid fuck
我说同步调用你他妈的愚蠢
I'm not readin the rest of that slop fuck you
我不会读剩下的内容了操你妈的
>implementation detail
>实施细节
wrong, I've said it all already and I'm not going to repeat, you have already demonstrated to ignore crucial details
错了,我已经说过了,我不再重复,你已经证明了忽略关键细节
>>109567371
a goroutine is just a green thread but rob gave it a different name because he is a gigantic faggot
goroutine 只是一条绿色线程,但 rob 给了它一个不同的名字,因为他是一个巨大的基佬
>>109567444
since Go 1.11, for the runtime it's the same thing but not for the user, because the user will only see blocking calls
从 Go 1.11 开始,对于运行时来说是一样的,但对于用户来说不是,因为用户只会看到阻塞调用
but before that goroutines where cooperatively scheduled and were not preemptive
但在此之前 goroutine 是合作调度的并且不是抢占式的
>>109567593
>since Go 1.11
>从 Go 1.11 开始
rather 1.14 I think
我认为是1.14
this says 1.11
这说的是1.11
https://github.com/golang/proposal/blob/master/design/24543-non-cooperative-preemption.md
but those say 1.14
但那些说1.14
>>109567038
eric lippert designed c#, you are doing it wrong and grasping at straws to justify your hacks because you don't want to accept that async / await is trash
eric lippert 设计了 c#,你做错了,并且抓住救命稻草来证明你的黑客行为是正确的,因为你不想接受 async/await 是垃圾
>>109567038
Your post is not marked async, nor is the entire reply chain it is part of; your argument is invalid.
您的帖子未标记为异步,它所属的整个回复链也未标记为异步;你的论点是无效的。
>>109567926
Appeal to authority; just because he's usually right, doesn't mean he's always right. I assume what he was really trying to say was "if you have to ask this question on stackoverflow, you don't understand enough about how async works in C# to reliably call those methods from a non-async method". Which is probably true, but doesn't mean that you can't do it safely and effectively. After all, it's not like async is magic - the compiler just transforms decorated methods into state machines on your behalf, so anything it can do you can do too.
诉诸权威;仅仅因为他通常是对的,并不意味着他总是对的。我认为他真正想说的是“如果你必须在 stackoverflow 上问这个问题,那么你对 C# 中的异步工作原理还不够了解,无法从非异步方法可靠地调用这些方法”。这可能是正确的,但并不意味着您不能安全有效地做到这一点。毕竟,异步并不像魔法一样 - 编译器只是代表您将修饰方法转换为状态机,因此它能做的任何事情您也可以做。
(I'm also not the guy you were arguing with before, I just got pissed off when I read that link because it's a shit answer that shouldn't be used to justify green threads)
(我也不是你之前争论的那个人,当我读到那个链接时我只是很生气,因为这是一个糟糕的答案,不应该用来证明绿色线程的合理性)
>>109568197
What?
>>109568225
>do it safely and effectively
>安全有效地做到这一点
by making assumptions about implementation details. will the thread chosen for an asyc task be determined after you decided to block yours? you are relying on undefined behavior that could either break or if abused by enough people hinder the progress of the platform. yes the programming model sucks. certainly none of the performance advantages of async / await apply in this cursed "sometimes async sometimes blocking" fashion because you got the worst of everything, an operating system thread is wasted, stacktraces suck and async / await gunk is present everywhere, getting ignored when inconvenient
通过对实施细节做出假设。在您决定阻止您的线程之后,是否会确定为异步任务选择的线程?您依赖于未定义的行为,这些行为可能会被破坏,或者如果被足够多的人滥用,则会阻碍平台的进步。是的,编程模型很糟糕。当然,async/await 的性能优势都不适用于这种被诅咒的“有时异步有时阻塞”的方式,因为你遇到了最糟糕的情况,操作系统线程被浪费,堆栈跟踪很糟糕,async/await 的垃圾无处不在,在不方便的时候被忽略
>>109569808
At some point you have to accept that the method you're calling isn't going to do something retarded. Maybe it has methods that aren't re-entrant or something, or it's not thread-safe, or any number of "implementation details" that you just kind of have to accept. It's the same with async - if you know your application doesn't do X, you don't have to worry about something that breaks if X happens. Normally that's bad practice, but honestly with async in C# the language has been moving away from the scenarios where it breaks - ex. ASP.NET Core removed the synchronization context that Framework-based ASP.NET used, specifically because now with async it's easier to not have to reason about it.
在某些时候,您必须接受您所调用的方法不会执行某些延迟的操作。也许它具有不可重入的方法或其他方法,或者它不是线程安全的,或者您必须接受的任何数量的“实现细节”。异步也是如此 - 如果您知道您的应用程序不执行 X,则不必担心如果 X 发生,某些事情就会中断。通常这是不好的做法,但老实说,对于 C# 中的异步,该语言已经远离了它中断的场景 - 例如。 ASP.NET Core 删除了基于框架的 ASP.NET 使用的同步上下文,特别是因为现在使用异步,更容易不必对其进行推理。
Stuff like stacktraces is an implementation detail of the CLR; in modern .NET (I think since like, 6?) an async method rolls up the stacktrace so you can see the continuation chain when you await it. And you can avoid blocking the OS thread as long as the underlying async operation actually yields the thread, which isn't your problem as the caller - if it didn't, it was going to tie up the threadpool thread anyway.
像堆栈跟踪这样的东西是 CLR 的实现细节;在现代 .NET 中(我认为从 6 开始?),异步方法会汇总堆栈跟踪,以便您在等待时可以看到延续链。只要底层异步操作实际上产生了线程,您就可以避免阻塞操作系统线程,这不是调用者的问题 - 如果没有,它无论如何都会占用线程池线程。
Ultimately I don't disagree that it's generally a bad idea to call an async method from a non-async one. Modern C# applications generally declare their entry-point to be async, and then that propagates virally down the whole callstack, which introduces the overhead of the compiler-generated state machine for basically no reason. But honestly, in practice, I haven't found it to matter much. It probably varies by domain - if you're programming a game in Unity, you're probably more aware of trying to avoid async methods, vs. an I/O-bound HTTP server.
最终,我不同意从非异步方法调用异步方法通常是一个坏主意。现代 C# 应用程序通常将其入口点声明为异步,然后在整个调用堆栈中病毒式传播,这基本上无缘无故地引入了编译器生成的状态机的开销。但老实说,在实践中,我发现这并不重要。它可能因领域而异 - 如果您在 Unity 中编写游戏,您可能会更清楚地尝试避免异步方法,而不是 I/O 绑定的 HTTP 服务器。
>>109570067
that was a reasoned response, thank you. yeah, in practice the throughput of the typical business application is rarely limited by whatever threading scheme you use. i know this is just a trolling thread but some anons seem to genuinely believe that the async / await model is doing them any favors when in practice they are blocking os threads anyway. they would be much better served by a model where blocking is cheap, i.e. green / virtual threads, but they are unable to admit that c# goofed in that department for some reason
这是一个合理的答复,谢谢。是的,实际上,典型业务应用程序的吞吐量很少受到您使用的任何线程方案的限制。我知道这只是一个恶搞线程,但一些匿名者似乎真诚地相信 async/await 模型对他们有好处,而实际上他们无论如何都会阻塞操作系统线程。他们会通过阻塞成本低的模型(即绿色/虚拟线程)更好地为他们服务,但他们无法承认 c# 由于某种原因在该部门犯了错误
(如果你觉得这篇文章有启发,可以点击这里付费)