This post has been de-listed (Author was flagged for spam)
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Okay so I have no idea on how to word this correctly, and i wanted to maybe get some keywords or ideas or something to achieve what I want to achieve.
Here's what I want to do: - I want to be able to run a single function asynchronously, many times. - The function is fast enough where the overhead of creating a new thread would outweigh the advantage of running it asynchronously. - I don't want to use a loop-and-flag system like below, as it would cause the thread to hog up all the CPU time:
```c int thread (void * unused) { while (true) { while (run_thread == false); // wait until run_thread = true run_thread = false; // ... } }
// to call it: run_thread = true; ```
- It'd be nice, but not necessary, to know when the function has completed later on in the program.
- It is guaranteed that there won't be more than one instance of the asynchronous function running at once.
I'm using SDL 1.2 in this program so any SDL 1.2 stuff I can use (long story, but I could use SDL2 if it was an option, but it's not in this case,) but using external libraries is okay if necessary. Additionally, I'm using Linux so WinAPIs aren't an option, either.
Also, it's okay if it's a very hacky and convoluted solution, my code is already a mess.
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/AskProgramm...