News for hackers. Stuff that matters.
Re:O(n^2), again, now in Windows Management Instrumentation by peter_d_sherman on Monday December 09, 2019 @11:40AM (#21744011)
Excerpt: "I decided that the interactions were too complex to be worth analyzing in detail, especially without any thread names to give clues about what the 25 different threads in svchost.exe (3024) were doing."

Future OS/Compiler Programming Note: It would be nice if threads could be individually named and those thread names shown/slowed/stopped/debugged in whatever tool implements Task Manager like functionality...

Re:O(n^2), again, now in Windows Management Instrumentation by muststopmyths on Monday December 09, 2019 @11:50AM (#21744112)
This already exists.

Windows had a janky way of naming threads before 10, but it has a supported API now.

The problem is that svchost is a host that runs a thread pool with various services being invoked as needed. You'd have to rename each thread every time you ran a function for a service.

That's probably more doable now with the supported API. The previous way involved raising an exception, so I can see why it wasn't done.

Seems like Windows has a more systemic testing problem though. We used to stress-test the crap out of various NT components back in the day. Don't know if the elimination of SDETs means there's no one doing that other than the NT perf team, which never did targeted stress.

Re:O(n^2), again, now in Windows Management Instrumentation by albertzeyer on Monday December 09, 2019 @11:58AM (#21744180)
For reference, this was the old API: https://docs.microsoft.com/en-us/visualstudio/debugger/how-t...

This was well known, and many applications actually used that. Of course it was very ugly. I don't think it would have been a problem to also rename a given thread multiple times, but not sure.

Re:O(n^2), again, now in Windows Management Instrumentation by jgalar on Monday December 09, 2019 @04:09PM (#21746610)
It's very ugly, but at least it doesn't seem to limit you to 15 characters like on Linux (prctl/pthread_set_name_np).

That limit makes it pretty hard to provide meaningful identifiers in a non-trivial application.

Re:O(n^2), again, now in Windows Management Instrumentation by brucedawson on Monday December 09, 2019 @06:38PM (#21747920)
Funny thing, windbg apparently uses a fixed-size buffer to store the old-style thread names and it must use strncpy to copy them in because if your thread names are long enough then windbg displays the first ~15 characters and then shows garbage, because strncpy doesn't guarantee null-termination.

Harmless I think, but sloppy.

Re:O(n^2), again, now in Windows Management Instrumentation by brucedawson on Monday December 09, 2019 @05:01PM (#21747102)
The "thread names" clause was a hyperlink to an article I wrote a few years listing all of the problems with thread naming on Windows. Microsoft took the suggestions seriously and basically landed all of the features and fixes that I requested, so now when I'm profiling or debugging Chrome the threads all have nice names.

I just kinda like trolling Microsoft for not using their own thread naming API very much.

https://randomascii.wordpress.com/2015/10/26/thread-naming-i...

Re:O(n^2), again, now in Windows Management Instrumentation by nitwit005 on Monday December 09, 2019 @08:57PM (#21748902)
I appreciate your efforts then. It's been a while since I was doing Windows development, but I remember staring at a bunch of hex values for thread IDs and despairing.
Re:O(n^2), again, now in Windows Management Instrumentation by masklinn on Monday December 09, 2019 @12:27PM (#21744441)
They can. Dawson specifically notes that there are no thread names here because he regularly harps on that subject e.g. https://randomascii.wordpress.com/2015/10/26/thread-naming-i... and https://randomascii.wordpress.com/2019/10/20/63-cores-blocke... ("plea for thread names" in the conclusion)
Re:O(n^2), again, now in Windows Management Instrumentation by retrovm on Monday December 09, 2019 @11:44AM (#21744046)
POSIX threads can be individually named. They inherit the name of their creator if you don't set one.
Re:O(n^2), again, now in Windows Management Instrumentation by adzm on Monday December 09, 2019 @11:57AM (#21744167)
They can be named in Windows as well, and this author has made pleas for developers to do so.
Re:O(n^2), again, now in Windows Management Instrumentation by jandrese on Monday December 09, 2019 @01:12PM (#21744877)
The caveat being the developers who are careful enough to name their threads and implement good debug hooks aren't the ones you get called on to fix their code.
Re:O(n^2), again, now in Windows Management Instrumentation by the-rc on Monday December 09, 2019 @01:49PM (#21745194)
As an aside, POSIX/Linux thread names have a limit of 16 bytes, which means 15 characters plus NULL. Speaking from experience, this can and will bite you when you need the names the most, if e.g. they are long, have just one or a handful of common prefixes and their creation is not entirely under your control.
Re:O(n^2), again, now in Windows Management Instrumentation by bobbyi_settv on Monday December 09, 2019 @02:08PM (#21745348)
That would help, but I think the root problem here (of the debugging difficulty, not the actual perf problem) is the Windows approach of having lots of unrelated services running together in a single process (svchost)
Re:O(n^2), again, now in Windows Management Instrumentation by pitterpatter on Monday December 09, 2019 @02:50PM (#21745766)
Since Windows 10 1703/1709, if you have at least 4G of RAM or so, every service will run in its own svchost (for the most part there may be some exceptions). There's some registry key to tweak how much RAM is needed to trigger this.
Re:O(n^2), again, now in Windows Management Instrumentation by colatkinson on Monday December 09, 2019 @11:48AM (#21744085)