caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Allsopp <dra-news@metastack.com>
To: malc <av1474@comtv.ru>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: RE: [Caml-list] Cross-platform cpu count
Date: Fri, 2 Sep 2011 13:05:27 +0000	[thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D9C2430D61@Remus.metastack.local> (raw)
In-Reply-To: <alpine.LNX.2.00.1109021650190.1519@linmac>

malc wrote:
> On Fri, 2 Sep 2011, David Allsopp wrote:
> 
> > malc wrote:
> > > On Fri, 2 Sep 2011, Daniel B?nzli wrote:
> > >
> > > > Hello,
> > > >
> > > > Can anybody confirm me that the following code works on cygwin :
> >
> > It won't - Sys.os_type returns "Cygwin" and getconf isn't in Cygwin
> > either - http://cygwin.com/ml/cygwin/2010-12/msg00435.html (actually,
> > it may be now - I haven't upgraded my Cygwin in a while - but it'll be
> > a recent addition)
> >
> > > >
> > > > let cpu_count () =
> > > >   try match Sys.os_type with
> > > >   | "Win32" -> int_of_string (Sys.getenv "NUMBER_OF_PROCESSORS")
> > > >   | _ ->
> > > >       let i = Unix.open_process_in "getconf _NPROCESSORS_ONLN" in
> > > >       let close () = ignore (Unix.close_process_in i) in
> > > >       try Scanf.fscanf i "%d" (fun n -> close (); n) with e ->
> > > > close ();
> > > raise e
> > > >   with
> > > >   | Not_found | Sys_error _ | Failure _ | Scanf.Scan_failure _
> > > >   | End_of_file | Unix.Unix_error (_, _, _) -> 1
> > > >
> > > > Thanks,
> > > >
> > >
> > >
> http://repo.or.cz/w/apc.git/blob/55de75ccb853f5e4443fd484e5eb95e1342e72bd
> :
> > > /ml_apc.c
> >
> > The C code here uses a deprecated API call (probably for Windows NT 4
> > compatibility). If you do end up using a C stub, use GetSystemInfo
> > (http://msdn.microsoft.com/en-us/library/ms724381(v=vs.85).aspx) -
> > it's easier to call. It's used in the OCaml runtime - see
> byterun/win32.c.
> > Personally, even for something where it's unimportant, I'd be nervous
> > relying on an environment variable (which can be edited...)
> 
> Uhm, no, it uses native API which was never publically documented to
> begin with, and the reason for that that it provides other information
> which is unavailable via other means.

It is documented and it is deprecated for this usage (see http://msdn.microsoft.com/en-us/library/ms725506(v=VS.85).aspx) making it a poor example for the specific question of querying logical processor count.


David


  reply	other threads:[~2011-09-02 13:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-02  0:04 Daniel Bünzli
2011-09-02  0:38 ` malc
2011-09-02  0:47   ` Daniel Bünzli
2011-09-02  7:39   ` David Allsopp
2011-09-02 10:03     ` Daniel Bünzli
2011-09-02 12:51     ` malc
2011-09-02 13:05       ` David Allsopp [this message]
2011-09-02 13:42         ` malc
2011-09-02  7:51 ` Richard W.M. Jones
2011-09-02  8:19   ` David Allsopp
2011-09-02 14:58     ` Richard W.M. Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E51C5B015DBD1348A1D85763337FB6D9C2430D61@Remus.metastack.local \
    --to=dra-news@metastack.com \
    --cc=av1474@comtv.ru \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).