I'm currently working with a microcontroller using the ESP-IDF framework, and as I'm improving my project, I realize I need to implement asynchronous tasks. However, threads can be quite costly, and I'm wondering if there are methods in C similar to async/await in other languages, or maybe something like Go routines? Any suggestions or alternatives would really help me out. Thanks!
3 Answers
In the past, we had CThreads, but I'm not sure if they're still a viable option today. Depending on your specific requirements, you might find it beneficial to create a custom cooperative thread library using function pointers and Yield() calls, which could simplify things by avoiding most locks and complexity.
The ESP-IDF framework includes an event loop library and interrupt handling mechanisms that can help achieve asynchronous functionality. Just a heads up, C doesn't have built-in async/await features, so if that's what you're looking for, you might need to switch to C++.
Creating my own system sounds beneficial! It will definitely help me grasp the concepts better.
You could set up a small state machine with function pointers that would help manage states instead of using threads. It can effectively handle many async-like behaviors without the overhead of threading.
Haha, I hear you! I’m just starting to explore beyond basic C, so this sounds like a good challenge.