4

I'm trying to compile Boost 1.49.0 for WinRT. I've got it down to one method: GetSystemInfo(), which is used in boost::thread::hardware_concurrency() to obtain the number of logical processors on the system.

I haven't found any replacement in WinRT yet.

Is there an alternative method I could use?

svick
  • 236,525
  • 50
  • 385
  • 514
Cygon
  • 9,444
  • 8
  • 42
  • 50
  • 1
    Note that Visual C++ 11 supports the C++11 thread and atomics libraries; you might consider using that instead of Boost.Thread. The libraries are very similar. – James McNellis Apr 13 '12 at 00:46
  • Thanks! This is for compiling an existing, cross-platform project that can use either TBB, Poco or Boost.Threads. Boost.Threads was the only one easily portable (this being the only and final method I hadn't found a WinRT replacement for yet). – Cygon Apr 13 '12 at 10:30

3 Answers3

11

You can call the Windows API function GetNativeSystemInfo, which is permitted in Metro style apps.

James McNellis
  • 348,265
  • 75
  • 913
  • 977
  • That's true, but Lord is that undiscoverable. – Hans Passant Apr 13 '12 at 00:13
  • 4
    @PatrickKlug: I was familiar with this API function and it was a lucky guess :-). In theory, all of the Windows API functions accessible from Metro style apps are listed in [this section of the Windows Dev Center](http://msdn.microsoft.com/en-us/library/windows/apps/br205757). This particular function is in fact listed (under "System"). I don't know, though, how complete the list is. There's a lot of good stuff from the WinAPI that is still usable, though. Also, the entire C and C++ Standard Library components are usable, and that's quite useful too. – James McNellis Apr 13 '12 at 06:07
  • @HansPassant: Your comment is well-taken. Ideally, I think the documentation for `GetSystemInfo` should say something like "Pssst! Hey you! Are you building a Metro style app? If so, use `GetNativeSystemInfo` instead!" I'll suggest that perhaps we can make the alternative functions clearer in the documentation. – James McNellis Apr 13 '12 at 06:08
3

There doesn't seem to be a simple way to get this information in WinRT. If you just want to know the processor architecture then you can use Windows.System.ProcessorArchitecture but this will not tell you how many logical CPUs are available. Windows.System.Threading doesn't tell you this information either.

To get information about the physical CPU I've found this question on the MSDN forum which suggests that we can use DeviceEnumeration to get to this information. By using the GUID for GUID_DEVICE_PROCESSOR ({97FADB10-4E33-40AE-359C-8BEF029DBDD0}) you can enumerate over all processors.

In Javascript this should look something like this - for a C++ example see the Device Enumeration example on MSDN:

Windows.Devices.Enumeration.DeviceInformation.findAllAsync('"System.Devices.InterfaceClassGuid:="{97FADB10-4E33-40AE-359C-8BEF029DBDD0}""')
.then(function (info) {
    for (var i = 0; i < info.length; i++) {
        var device = info[i];
    }
});

On my machine this gives me all sorts of devices, sound card, PCI and USB processors so I'm not sure if there is a better way to just get the CPU but I did get the info what CPU I have

"Intel(R) Core(TM) i7 CPU       Q 740  @ 1.73GHz"

Unfortunately this info doesn't seem to include a simple flag that tells you the number of CPUs and therefore I think it would be difficult to get to a number of logical CPUs. I suggest you ask on the MSDN forum. They are usually quite responsive.

Patrick Klug
  • 14,056
  • 13
  • 71
  • 118
  • I'll leave this answer in case anyone stumbles upon this question in the search how to get to the processor information. – Patrick Klug Apr 20 '12 at 00:26
  • 1
    I just got this working in C# and the results it returns is one result for logical core. E.g. my Core i7 950 returns eight results, each with the same name. In the example above using the guid, info.length would be the number of cores. – Adrian Nov 07 '12 at 10:53
0

System.Environment.ProcessorCount should give you the number of cores.

Lee Richardson
  • 8,331
  • 6
  • 42
  • 65