Dlang D language z biblioteką Phobos. Wątki i Komunikacja Klient-Serwer

0

Proszę o wytłumaczenie mi, jak wykorzystać dane przykłady dla moich celów.

Kompilator Dlang

  1. Phobos core_thread
    Chcę stworzyć listę wątków, gdzie każdemu z nich podczas tworzenia będzie podawany real a. Wątek będzie wypisywał w konsoli sin(a) zwracał sin(a).
    Chcę przeciążyć operator "sin" tak aby rozpoczynał nowy wątek, aby wypisywał w konsoli sin(a) zwracał sin(a).
    input
    2
    1,2,3,4,5
    sin 8
    outuput
    a= 2 sin(2) = 0.909
    a= 1 sin(1) = 0.84
    a= 2 sin(2) = 0.909
    a= 3 sin(3) = 0.141
    a= 4 sin(4) = -0.75
    a= 5 sin(5) = -0.95
    a=8 sin(8 radius) = 0.989

  2. Kod który uruchamia aplikację serwerową, która oblicza sin z argumentu.
    Chcę uruchomić aplikację na danym adresie i porcie, która działa podobnie jak pierwszy przykład.
    Za pomocą aplikacji klienta chcę wysyłać do serwera argument auto a i otrzymywać wynik sin(a).
    Nadal muszę przeciążyć operator "sin"

Tu moje kody jakie udało się doprowadzić do kompilacji:

import std.stdio;
import core.thread;
import core.math;

class DerivedThread : Thread
{
    this()
    {
        super(&run);
    }

private:
    void run()
    {
        // Derived thread running.
    }
}

void threadFunc()
{
    // Composed thread running.
}

class Klasa
{
	int a; //to raczej nie potrzebne

	this()
	{
		a=0;  //to raczej nie potrzebne
	}

private:
	real sinus(real liczba){
		write("a = ");
		writeln(liczba); 
		write("sin(a)= ");
		writeln(sin(liczba));
		return sin(liczba);
		}

}



void main() {

// create and start instances of each type
auto derived = new DerivedThread().start();
auto composed = new Thread(&threadFunc).start();
new Thread({
    // Codes to run in the newly created thread.
}).start();
  
 	string c = "Witaj swiecie";
	writeln(c);
  }

Jak przeciążyć operator "sin "?
Jak wrzucić go aby był możliwy do użycia?
Jak podać listę argumentów do funkcji?

Tu pojawi się drugi kod.
0
void main()
{
    import std.concurrency;
    import std.stdio: write, writeln, writef, writefln;
    __gshared string received;
    static void spawnedFunc(Tid ownerTid)
    {
        import std.conv : text;
        // Receive a message from the owner thread.
        receive((int i){
            received = text("Received the number ", i);
    
            // Send a message back to the owner thread
            // indicating success.
            send(ownerTid, true);
        });
    }
    
    // Start spawnedFunc in a new thread.
    auto childTid = spawn(&spawnedFunc, thisTid);
	
	int[] tablica;
	/*	
    for(Tid i; i<10;i++){
		tablica[i]= spawn(&spawnedFunc, thisTid);
		send(tablica[i],i+11); 
	}
	*/
	
	auto jeden = spawn(&spawnedFunc, thisTid);
	auto dwa = spawn(&spawnedFunc, thisTid);
	auto trzy = spawn(&spawnedFunc, thisTid);
	
    // Send the number 42 to this new thread.
    send(childTid, 99);
	    // Receive the result code.
    auto wasSuccessful = receiveOnly!(bool);
    assert(wasSuccessful);
    writeln(received); // "Received the number 42"
	send(jeden, 1);
	    // Receive the result code.
     wasSuccessful = receiveOnly!(bool);
    assert(wasSuccessful);
    writeln(received); // "Received the number 42"
	send(dwa, 2);
	    // Receive the result code.
    wasSuccessful = receiveOnly!(bool);
    assert(wasSuccessful);
    writeln(received); // "Received the number 42"
	send(trzy, 3);
	    // Receive the result code.
     wasSuccessful = receiveOnly!(bool);
    assert(wasSuccessful);
    writeln(received); // "Received the number 42"
    
    // Receive the result code.
     wasSuccessful = receiveOnly!(bool);
    assert(wasSuccessful);
    writeln(received); // "Received the number 42"
    
    
}
0
    import core.thread;
    import std.stdio: write, writeln, writef, writefln;
	import std.array;
	import std.conv;
	

int zwracamy(int demo){return demo++;}



class DerivedThread : Thread
{
 int a;
	this(int b){
	super(&run);
	a=b;
	}
void geta(){
writeln("watek= ",a);
//writeln(a);

} 

private:
    void run()
    {
        // Derived thread running.
    }
}
	
void main(string[] arguments)
{
if (arguments.length>1){
arguments=split(arguments[1],",");
writeln(arguments);

int[] tablicaa;
foreach(string i;arguments){
	tablicaa ~= to!int(i);
	writeln(i);
	
	}
writeln(tablicaa);

DerivedThread[] tablica;  

}else {writeln("Brak Argumentu");}
 
}

Oto do czego udało mi się dojść w próbach uruchomienia wątków

1 użytkowników online, w tym zalogowanych: 0, gości: 1