Threads

Tim tim.moldazhan at gmail.com
Wed Mar 22 05:30:41 UTC 2023


Hello! I am trying to make a simple multi-threading application. 
But I get an error when I run the main thread of the program in a 
thread. The question is: "How to pass arguments from the main 
thread to the newly created thread of itself". Here is a piece of 
code:

module main;
import app;
import core.thread;

int main(string[] args)
{

     static int result;
     static string[] args_copy;

     static void app_thread()
     {
         App app = new App();
         result = app.run(args_copy); //<-- Exception; static int 
App.run(string[] args)
         
//object.Exception@/usr/include/dmd/phobos/std/getopt.d(423):
         // Invalid arguments string passed: program name missing
     }

     args_copy = args; //Why program name is missing while copy 
arguments?

     // Running app interface in a thread;
     Thread thread = new Thread(&app_thread).start();
     thread.join();

     return result;
}



More information about the Digitalmars-d-learn mailing list