▲ | achierius 3 days ago | |||||||
How do you insert a branch "every 10ms" without some sort of hardware-provided interrupt? If your code is running in a hot loop, you would have to insert that branch into the hot loop (even well-predicted branches add a few cycles, and can do things like break up decode groups) or have the hot loop bail out every once in a while to go execute the branch and code, which would mean tiling your interior hot loop and thus adding probably significant overhead that way. Also, you say "cached memory address" but I can almost guarantee that unless you're doing that load a lot more frequently than once every 10 milliseconds the inner loop is going to knock that address out of l1 and probably l2 by the time you get back around to it. | ||||||||
▲ | hedora 2 days ago | parent [-] | |||||||
You put the check outside the innermost loop. Put it up one or two loops instead, and reason that the check runs frequently enough and also infrequently enough. Also, don’t you have to hit a pthread cancellation point for pthread_cancel to take effect? Those are way more expensive than a branch, but if you want the exact behavior, you could do “if (done) { break; } else { pthread_??? }” | ||||||||
|