我怎样才能像在 go 中那样在 C 中实现并发?
How can i implement concurrency in C like we do in go?
我想在 C 中实现 go 的并发,因为我看到它提高了 go 的[性能]。我没有尝试任何东西,因为我不明白要尝试什么。我该怎么做?
协程在 C 中本机不可用(尽管从 C++20 开始,它们在 C++ 中受支持),因此您将依赖外部库,或者您必须自己实现一些东西。
一些有用的资源:an example by Simon Tatham, another small example, a C library called libaco
, an interesting article with an alternative approach。
另一种方法可能是使用事件循环,这与 JavaScript 用于在单个线程内实现并发的方法相同。最常用的库之一是 libuv
and here's a small example of using libuv
.
我想在 C 中实现 go 的并发,因为我看到它提高了 go 的[性能]。我没有尝试任何东西,因为我不明白要尝试什么。我该怎么做?
协程在 C 中本机不可用(尽管从 C++20 开始,它们在 C++ 中受支持),因此您将依赖外部库,或者您必须自己实现一些东西。
一些有用的资源:an example by Simon Tatham, another small example, a C library called libaco
, an interesting article with an alternative approach。
另一种方法可能是使用事件循环,这与 JavaScript 用于在单个线程内实现并发的方法相同。最常用的库之一是 libuv
and here's a small example of using libuv
.