Can a function run independently inside a main app? [OpenMP]
Say we have a function that does not interfere with other data and runs independently. However, I heard a method to do it is to make the whole app in to a section and that alone a section. Can it be done instead with the main app spawning it into a thread and ensuring that the main app will not wait for it to end?
e.g. pseudo code:
int main (void) {
<do stuff on thread 0>
<do stuff on thread 0>
<spawn independent function on thread 1 with no waiting>
<do stuff on thread 0>
<d开发者_如何学Goo stuff on thread 0>
}
EDIT: Can it be done with another philosophy completely? (no OpenMP)
This isn't OpenMP's prime goal: it was built for parallel processing, not concurrent programming. Check your local thread library and look for something called "daemon threads", "detached threads" or similar.
If you are referring to detached threads, then the answer is yes. The thread runs, then exits without having to be waited for. You lose the ability to get a return status from the thread.
Larsmans post points out why you probably do not want to use threading
精彩评论