[m-rev.] diff: implement num_processors/4 for C#

Julien Fischer jfischer at opturion.com
Fri Aug 15 17:54:31 AEST 2025


Implement num_processors/4 for C#.

library/thread.m:
    As above.

    Delete some unnecessary foreign code attributes.

Julien.

diff --git a/library/thread.m b/library/thread.m
index ae157fbe5..029742edd 100644
--- a/library/thread.m
+++ b/library/thread.m
@@ -1236,18 +1236,24 @@ num_processors(MaybeProcs, !IO) :-
     Success = (Procs > 0) ? MR_YES : MR_NO;
 ").

+:- pragma foreign_proc("C#",
+    num_processors(Procs::out, Success::out, _IO0::di, _IO::uo),
+    [promise_pure, thread_safe, will_not_call_mercury,
+     will_not_throw_exception],
+"
+    Procs = System.Environment.ProcessorCount;
+    Success = mr_bool.YES;
+").
+
 :- pragma foreign_proc("Java",
     num_processors(Procs::out, Success::out, _IO0::di, _IO::uo),
     [promise_pure, thread_safe, will_not_call_mercury,
-     will_not_throw_exception, tabled_for_io],
+     will_not_throw_exception],
 "
     Procs = Runtime.getRuntime().availableProcessors();
     Success = bool.YES;
 ").

-% On other backends se don't know how to determine this yet.
-num_processors(0, no, !IO).
-
 %---------------------------------------------------------------------------%
 :- end_module thread.
 %---------------------------------------------------------------------------%


More information about the reviews mailing list