Threads

Tim tim.moldazhan at gmail.com
Wed Mar 22 08:43:42 UTC 2023


On Wednesday, 22 March 2023 at 07:16:43 UTC, Kagamin wrote:
> static is thread local by default.
>
> ```
> module main;
> import app;
> import core.thread;
>
> int main(string[] args)
> {
>      static shared int result;
>      static shared string[] args_copy;
>
>      static void app_thread()
>      {
>          App app = new App();
>          result = app.run(args_copy);
>      }
>
>      args_copy = cast(shared)args;
>
>      // Running app interface in a thread;
>      Thread thread = new Thread(&app_thread).start();
>      thread.join();
>
>      return result;
> }
> ```

It seems work, but I have to change "int App.run(string[] args)" 
to "App.run(shared string[] args)" in app module and 
`std.getopt.getopt` throws me an error in the same module:

Error: none of the overloads of template `std.getopt.getopt` are 
callable using argument types `!()(shared(string[]), string, 
string, string*)`
/usr/include/dmd/phobos/std/getopt.d(420,14):        Candidate 
is: `getopt(T...)(ref string[] args, T opts)`





More information about the Digitalmars-d-learn mailing list