How can i implement concurrency in C like we do in go?

huangapple go评论87阅读模式
英文:

How can i implement concurrency in C like we do in go?

问题

我想在C语言中实现Go语言的并发,因为我看到它可以提高Go语言的性能。我还没有尝试过任何方法,因为我不知道该如何开始。请问我应该如何做呢?

英文:

I would like to implement go's concurrency in C because I have seen that it increases the [performance] of go. I have not tried anything because I can't understand what to try. How can I do that?

答案1

得分: 1

协程在C语言中不是原生支持的(尽管从C++20开始支持),所以你需要依赖外部库或者自己实现一些东西。

一些有用的资源:Simon Tatham的一个示例另一个小例子一个名为libaco的C库一篇使用另一种方法的有趣文章

另一种方法是使用事件循环,这是JavaScript用来在单个线程中实现并发的方法。其中最常用的库之一是libuv这里有一个使用libuv的小例子

英文:

Coroutines are not available in C natively (although they're supported in C++ starting with C++20), so you're going to rely on external libraries or you'll have to implement something yourself.

Some useful resources: an example by Simon Tatham, another small example, a C library called libaco, an interesting article with an alternative approach.

Another approach could be using an event-loop, that is the same approach used by JavaScript to implement concurrency within a single thread. One of the most used libraries is libuv and here's a small example of using libuv.

huangapple
  • 本文由 发表于 2021年9月26日 21:26:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/69335384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定