[m-rev.] for review: disable concurrency in non .par LLDS grades
Julien Fischer
jfischer at opturion.com
Thu Aug 21 15:48:34 AEST 2025
On Thu, 21 Aug 2025 at 13:24, Peter Wang <novalazy at gmail.com> wrote:
>
> On Thu, 21 Aug 2025 13:05:54 +1000 Julien Fischer <jfischer at opturion.com> wrote:
> > For review by Peter.
> >
> > -----------------------------------------------
> >
> > Disable concurrency in non .par LLDS grades.
> >
> > The non .par LLDS grades currently "support" concurrency. However, this support
> > is really on usable with a small few benchmark programs, due to the inability
> > of the implementation to switch threads if the executing thread blocks. Disable
> > this capability by causing spawn/3 to abort if used in non .par LLDS grades.
> >
> > library/thread.m:
> > Make the above change to spawn/3.
> >
> > compiler/globals.m:
> > Update the code that checks if the current grade supports concurrency.
>
> Mention it in NEWS.
>
> The help text for --parallel might need to be updated.
There's a revised diff below
> That should be fine, but there may be other documentation to update.
Given that there other changes in this area in the pipeline, it's probably not
terribly important that it all be updated now.
Julien.
diff --git a/NEWS.md b/NEWS.md
index fb20646b4..c40f159c5 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -100,6 +100,9 @@ Changes that may break compatibility
* We have replaced the `--no-warn-only-one-format-string-error` compiler
option with the new option named `--warn-all-format-string-errors`.
+* We have disabled support for concurrency in non-parallel low-level C grades.
+ It was never useful for anything other than trivial programs.
+
Changes to the Mercury standard library
---------------------------------------
diff --git a/compiler/globals.m b/compiler/globals.m
index 576a3d9ff..ec1d61edf 100644
--- a/compiler/globals.m
+++ b/compiler/globals.m
@@ -1226,16 +1226,8 @@ current_grade_supports_concurrency(Globals,
ThreadsSupported) :-
globals.get_target(Globals, Target),
(
Target = target_c,
- globals.lookup_bool_option(Globals, highlevel_code, HighLevelCode),
- % In high-level C grades we only support threads in .par grades.
- (
- HighLevelCode = no,
- ThreadsSupported = yes
- ;
- HighLevelCode = yes,
- globals.lookup_bool_option(Globals, parallel, Parallel),
- ThreadsSupported = Parallel
- )
+ globals.lookup_bool_option(Globals, parallel, Parallel),
+ ThreadsSupported = Parallel
;
( Target = target_java
; Target = target_csharp
diff --git a/compiler/options.m b/compiler/options.m
index 46e70d2f1..d3bf6ed95 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -2076,7 +2076,8 @@ optdb(oc_grade_etc, parallel,
bool(no),
"(grade modifier: @samp{.par})", [
cindex(".par (grade modifier"),
% XXX These two should be *different* grade modifiers.
- w("Enable parallel execution support for the low-level C grades."),
+ w("Enable concurrency and parallel conjunction support for the"),
+ w("low-level C grades."),
w("Enable concurrency (via pthreads) for the high-level C grades.")])).
optdb(oc_grade_etc, maybe_thread_safe_opt, string("no"),
% XXX How is a yes/no argument better than a no- prefix?
diff --git a/library/thread.m b/library/thread.m
index 029742edd..0417a8368 100644
--- a/library/thread.m
+++ b/library/thread.m
@@ -251,7 +251,7 @@ can_spawn :-
can_spawn_context,
[will_not_call_mercury, promise_pure, thread_safe, may_not_duplicate],
"
-#if !defined(MR_HIGHLEVEL_CODE)
+#if !defined(MR_HIGHLEVEL_CODE) && defined(MR_THREAD_SAFE)
SUCCESS_INDICATOR = MR_TRUE;
#else
SUCCESS_INDICATOR = MR_FALSE;
diff --git a/tests/warnings/help_text.err_exp b/tests/warnings/help_text.err_exp
index 234ec7a8d..0cf741457 100644
--- a/tests/warnings/help_text.err_exp
+++ b/tests/warnings/help_text.err_exp
@@ -571,8 +571,8 @@ Grade options
floats. This option is supported only when targeting C.
--parallel (grade modifier: `.par')
- Enable parallel execution support for the low-level C grades. Enable
- concurrency (via pthreads) for the high-level C grades.
+ Enable concurrency and parallel conjunction support for the low-level C
+ grades. Enable concurrency (via pthreads) for the high-level C grades.
--maybe-thread-safe {yes, no}
Specify how the compiler should treat the `maybe_thread_safe' foreign
More information about the reviews
mailing list