[m-rev.] for review: Add thread.spawn_native/5 with minimum stack size option.

Julien Fischer jfischer at opturion.com
Wed Oct 27 11:35:58 AEDT 2021


Hi Peter,

On Tue, 26 Oct 2021, Peter Wang wrote:

> library/thread.m:
>    Add thread_options type, and a variant of the spawn_native predicate
>    that takes a thread_options argument.
>
>    The only thread option supported so far is to request a minimum
>    stack size for the newly created thread. This is only implemented
>    for POSIX threads so far.

...


> diff --git a/library/thread.m b/library/thread.m
> index 401ab8ab7..7f70e5d4b 100644
> --- a/library/thread.m
> +++ b/library/thread.m
> @@ -3,7 +3,7 @@
> %---------------------------------------------------------------------------%
> % Copyright (C) 2000-2001, 2003-2004, 2006-2008, 2010-2011 The University
> % of Melbourne.
> -% Copyright (C) 2014-2018 The Mercury Team.
> +% Copyright (C) 2014-2021 The Mercury Team.
> % This file is distributed under the terms specified in COPYING.LIB.
> %---------------------------------------------------------------------------%
> %
> @@ -67,7 +67,31 @@
> :- pred spawn(pred(thread, io, io), maybe_error(thread), io, io).
> :- mode spawn(pred(in, di, uo) is cc_multi, out, di, uo) is cc_multi.
> 
> -    % spawn_native(Closure, Res, IO0, IO):
> +    % A type representing options that affect thread creation.
> +    %
> +:- type thread_options.

...

> +    % Create a new thread options object.
> +    %
> +:- func init_thread_options = thread_options.

I think you need to add:

      ... with the options set to their default values.

and then describe what those defaults are.  The latter can be done
either here or in the comment above the predicate that sets the
respective option.

(Another possibility would be to rename init_thread_options/0 to
default_thread_options/0.)

> +
> +    % Set the minimum stack size (in bytes) for a new thread created with these
> +    % thread options. Only affects POSIX threads backend. The Java and C#
> +    % backends do not yet respect the minimum stack size option.

Replace the second sentence with:

     This only affects C grades that use POSIX threads.

> +    %
> +    % The special value 0 means to use the default stack size of the underlying
> +    % environment.
> +    %
> +:- pred set_min_stack_size(uint::in, thread_options::in, thread_options::out)
> +    is det.

The diff looks fine otherwise.

Julien.


More information about the reviews mailing list