Task 0 never appears to execute.
Task 1 does not wait the 4 seconds.
Program never exits.
Yes, calling the same function simultaneously is bad
If I have any utility function then should I safecall or inline it so program doesn't go into this weird state if more than one task accesses it?
If I have a single function that needs to be run to control multiple items, should I either inline it or refactor it to handle all items in one function (essentially do my own poor man's scheduling)? Some of these functions are 60 lines of code. Inlining just seems wrong
afanofosc wrote:Fortunately, you can make your functions and the ones they call inline and not worry about the resulting code size or function call safety. Or you can write your functions in a way that works well with safecall (i.e., keep the long running loops outside the shared functions).
Another way to think about the dichotomy of safecall and inline is that with safecall you share the function code during runtime, but with inline you share the code during compile time. To me, that makes inline rather like a preprocessor macro although it use has several advantages over preprocessor macros (e.g., the compiler checks arguments for type and local variables can be declared).
Which way is better? As usual, I would say there is no single rule -- it depends on what you are trying to accomplish and what your programming style favors.
Yes, inline functions are very handy. C++ inline functions, for the most part, replace the C macros for the same reason. You get the optimizations with all the function compile-time checks (type safety, etc).
If I need the function running simultaneous, I'll have to inline. safecall will serialize them.