Is it possible to implement coroutine with threads? [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
All in title. Since coroutine just need a sort of EIP memory, and thread provides that, is it possible to do it? That's way to have a highly portable coroutine library.

You can implement coroutines / generators based on threads or even fibers. But they would be less performant compared to implementations like msvc or gcc provide.
I implemented coroutines that way (no threads, but fibers) in delphi. You need to estimate how much stack-memory do you need, you need to create those threads (which is heavy...).
So you should avoid that.

Related

Utilization of atomic_flag on C++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am beginner in concurrent programming on C++. I read about std::atomic_flag and I don't understand where this atomic_flag can be useful. Maybe someone can explain me for which tasks atomic_flag can be useful
cppreference.com has a usage example. It also contains the following explanatory note:
Unlike all specializations of std::atomic, it is guaranteed to be lock-free.
In other words: you’d use it the same way you would use std::atomic<bool> but with the added guarantee of lock-freeness (though on most systems std::atomic<bool> will also be lock-free, i.e. std::atomic<bool>::is_always_lock_free will be true).

Would it be safe, effective and still flexible to use RAII approach in C++ with WinAPI? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
A lot of WinAPI objects, such as handles, events or sockets, are resources. I found it safe and efficient to wrap them in RAII classes.
Are there any pitfalls in doing that? Is it common practice or, instead, a bright, misleading idea? Or, maybe, there are already libraries for that? (Although I couldn't find anything worthy.)
Mostly, I'm interested in wrappers for 'small' objects like files, sockets, events and threads, that are not related to GUI or COM. Libraries like MFC or ATL may do such job but don't seem to be lightweight and no-overhead what I'm asking about.

Thread Loop with Sleep() or SetTimer [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have an Win32 app that contains 13 SetTimer() calls... I have a doubt: to optimize application performance, would be better to use CreateThread (with infinite loop and Sleep) instead SetTimer? Which of the two ways to a better way and timing of actions?
Sorry for bad english, thanks in advance!
I wouldn't write a custom timer unless you have a very specific need to do so. I'd guess performance difference would be negligible for most applications. Plus you'll run into other issues I'm sure you're not currently considering, like data synchronization, communicating with your GUI thread for user interactions, etc. It's possible you could even make performance worse.
If you feel you have a specific need, state what that need is and maybe we can guide the answer.

TCP vs Shared Memory? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I understand, if shared memory is used correctly it can be faster than any other kind of IPC. My question is a bit more specific: If I transfer many small packets, eg 100 bytes, from different programs to one main program, what kind of speed difference can I expect?
The benefit from using shared memory will not be so much, because you will end up with using conditional variables on the shared memory (cf. pthread_condattr_setpshared; it will be a substantial coding work, by the way.) Then your logic is governed by the OS scheduler, and it's not very different from using localhost TCP connection which has a different and fast implementation than standard TCP on most OS.
If it's OK to entirely rely on a spinlock on the shared mem, then you will indeed realize substantial speed up like x3 fold.

Runtime add algorithm to a program [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm creating a program that make some matrix analysis. Now i want to implement some basic algorithms but I need to allow users implement new algorithms in the future without recompile the code.
I suppose that these algorithms already exist, probably in c/c++ language.
How can I do it if I use qt?
Maybe it's better use an other programming language and why?
I suppose that these algorithms already exist, probably in c/c++ language
If that's so, one way would be to write your program capable of loading DLLs, and then your users can compile their own algorithm DLL plugins for your application.
Or if you don't expect your users to be able to compile the existing c/c++ algorithms, maybe you can do as Joachim Pileborg suggests, and add in a scripting interface.