英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论