Identifying a new thread in another process...

Started by
21 comments, last by Idov 13 years, 4 months ago
OK... so you're hung up on a single if() statement check to filter out the threads you don't want, versus having to do some serious low-level hackery to intercept thread spawn calls?

Priority check [wink]

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Advertisement
Quote:Original post by ApochPiQ
OK... so you're hung up on a single if() statement check to filter out the threads you don't want, versus having to do some serious low-level hackery to intercept thread spawn calls?

Priority check [wink]


Yes, but I'm calling "Thread32Next" for each thread every time I'm looking for the threads I want. It's not just one "if" statement.
Quote:Original post by Idov
Quote:Original post by ApochPiQ
OK... so you're hung up on a single if() statement check to filter out the threads you don't want, versus having to do some serious low-level hackery to intercept thread spawn calls?

Priority check [wink]


Yes, but I'm calling "Thread32Next" for each thread every time I'm looking for the threads I want. It's not just one "if" statement.


I'm assuming you are worried about performance? On my machine, I currently have 552 threads running. An overhead of ~550 if() statements per sample frame is completely negligible on any modern CPU. It's a fraction of a fraction of a percent of what a CPU is capable of, and won't skew your results in any meaningful way.
Quote:Original post by kuroioranda
Quote:Original post by Idov
Quote:Original post by ApochPiQ
OK... so you're hung up on a single if() statement check to filter out the threads you don't want, versus having to do some serious low-level hackery to intercept thread spawn calls?

Priority check [wink]


Yes, but I'm calling "Thread32Next" for each thread every time I'm looking for the threads I want. It's not just one "if" statement.


I'm assuming you are worried about performance? On my machine, I currently have 552 threads running. An overhead of ~550 if() statements per sample frame is completely negligible on any modern CPU. It's a fraction of a fraction of a percent of what a CPU is capable of, and won't skew your results in any meaningful way.


ok, but it's not the "if" statement that worry me.
it's the "Thread32Next" that i'm afraid of.
Is this what you meant? that the "Thread32Next" doesn't affect the performance?
Quote:Original post by Idov
Quote:Original post by kuroioranda
Quote:Original post by Idov
Quote:Original post by ApochPiQ
OK... so you're hung up on a single if() statement check to filter out the threads you don't want, versus having to do some serious low-level hackery to intercept thread spawn calls?

Priority check [wink]


Yes, but I'm calling "Thread32Next" for each thread every time I'm looking for the threads I want. It's not just one "if" statement.


I'm assuming you are worried about performance? On my machine, I currently have 552 threads running. An overhead of ~550 if() statements per sample frame is completely negligible on any modern CPU. It's a fraction of a fraction of a percent of what a CPU is capable of, and won't skew your results in any meaningful way.


ok, but it's not the "if" statement that worry me.
it's the "Thread32Next" that i'm afraid of.
Is this what you meant? that the "Thread32Next" doesn't affect the performance?


Sorry, I misunderstood you, I actually was referring to the if() statements. But it applies to the Thread32Next() function as well.

Generally it's not worth worrying about the performance of individual function calls like that until you have actually had a profiler indicate they are using a significant amount of CPU time. It's easy to assume the worst (that it will be slow), but the reality is that it's probably not even going to be blip on your CPU.

If you're still nervous, though, why not try writing up a quick program that just loops over every thread in the system as many times as possible in one second, and see how many times you can do it? Then you will have quantifiable data to either back up or dispel your fears.
hmmm... that's a good idea.
thanks :)
NO!!!!!
I tried to run my program when it only gets the threads each sample and then again without getting the threads and found out that getting the threads takes almost all the CPU time...
I have about 700 threads in my system.

what should I do??? :(
Quote:Original post by Idov
I tried to run my program when it only gets the threads each sample and then again without getting the threads and found out that getting the threads takes almost all the CPU time...


Does your code actually... you know... do anything 'without getting the threads'?
yes :)
I think what MaulingMonkey means is that your loop that "does not get the threads" is probably being optimised away so that it doesn't even get run.

I assume your test code looks something like this:
// Getting threadsget timefor (...) {    call Thread32Next}get timecalculate time difference// Not getting threadsget timefor (...) {    // do nothing}get timecalculate time difference


If that is the case, then the first loop will just run as fast as it can, using 100% CPU. And the second loop will be optimised away so that it doesn't even run.

If that is not the case, then your code could probably be optimised, because i doubt that a single function call could use that much CPU. And you should post your code so that we know what you are talking about without having to guess.
[Window Detective] - Windows UI spy utility for programmers

This topic is closed to new replies.

Advertisement