Question about threads

Ary Manzana ary at esperanto.org.ar
Tue Apr 17 12:22:50 PDT 2007


Jari-Matti Mäkelä escribió:
> Ary Manzana wrote:
> 
>> class MyThread : Thread {
>>
>>     char fChar;
>>     this(char c) {
>>         fChar = c;
>>     }
>>     
>>     int run() {
>>         while(true)
>>             writef("%s", fChar);
>>         return 0;
>>     }
>>     
>> }
>>
>> void main(char[][] args) {
>>     MyThread t1 = new MyThread('.');
>>     MyThread t2 = new MyThread('!');
>>     
>>     t1.start();
>>     t2.start();
>> }
>> -----------------------------------------------
>>
>> Running the above program in Windows makes it crash (I get the "program
>> X encountered a problem and must be closed" message). Why is this
>> happenning?
> 
> You probably have to end the execution of t1 and t2 before returning
> from main().

Ok. So how can I implement this? It's strange for me that starting two 
threads and exiting main ends the application, since there are other 
threads alive.


More information about the Digitalmars-d-learn mailing list