Thread overview
Threading
Jan 20, 2003
Paul Stanton
Jan 20, 2003
Burton Radons
Jan 21, 2003
Paul Stanton
Jan 21, 2003
Burton Radons
Jan 21, 2003
Mark Evans
Jan 21, 2003
Mike Wynn
January 20, 2003
can anyone provide a SIMPLE example of thread use in D? thanks.


January 20, 2003

Paul Stanton wrote:
> can anyone provide a SIMPLE example of thread use in D? thanks.

import thread;

int thread1 (void *ptr)
{
    printf ("1: Start\n");
    Thread.yield ();
    printf ("1: Middle\n");
    Thread.yield ();
    printf ("1: End\n");
    return 0;
}

void main ()
{
    Thread t = new Thread (&thread1, null);

    t.start ();
    printf ("0: Thread started\n");
    Thread.yield ();
    printf ("0: Middle\n");
    while (t.isRunning ())
        Thread.yield ();
}

Should print:

0: Thread started
1: Start
0: Middle
1: Middle
1: End

January 21, 2003
thanks for your time.
wont compile: no property 'isRunning' for type 'Thread'.
fixed it like so....

1. added just below import : "enum TS {INITIAL,RUNNING,TERMINATED}" (copied form
thread.d)
2. changed "while(t.isRunning())" to "while (t.getState() == TS.RUNNING)"

not sure why thread.d doesnt expose constants for thread states, kind of means users have to guess... oh well, any better way to do this?

In article <3E2C82CA.20806@users.sourceforge.net>, Burton Radons says...
>
>Paul Stanton wrote:
>> can anyone provide a SIMPLE example of thread use in D? thanks.
>
>import thread;
>
>int thread1 (void *ptr)
>{
>     printf ("1: Start\n");
>     Thread.yield ();
>     printf ("1: Middle\n");
>     Thread.yield ();
>     printf ("1: End\n");
>     return 0;
>}
>
>void main ()
>{
>     Thread t = new Thread (&thread1, null);
>
>     t.start ();
>     printf ("0: Thread started\n");
>     Thread.yield ();
>     printf ("0: Middle\n");
>     while (t.isRunning ())
>         Thread.yield ();
>}
>
>Should print:
>
>0: Thread started
>1: Start
>0: Middle
>1: Middle
>1: End
>


January 21, 2003

Paul Stanton wrote:
> thanks for your time.
> wont compile: no property 'isRunning' for type 'Thread'.
> fixed it like so....

Whoops, accidentally used DLI code, sorry.

> 1. added just below import : "enum TS {INITIAL,RUNNING,TERMINATED}" (copied form
> thread.d)
> 2. changed "while(t.isRunning())" to "while (t.getState() == TS.RUNNING)"

That would have to be Thread.TS.RUNNING or t.TS.RUNNING, wouldn't it?

> not sure why thread.d doesnt expose constants for thread states, kind of means
> users have to guess... oh well, any better way to do this?

The properties should absolutely be in the API, so that should be amended soon.

January 21, 2003
You might be interested to know that Oz supports literally thousands of concurrent threads with no sweat.  D could learn some things from Oz.

Mark


January 21, 2003
more than the underlying OS will allow ?
and does it allow easy acces to thread locals ?

"Mark Evans" <Mark_member@pathlink.com> wrote in message news:b0it8a$2a0r$1@digitaldaemon.com...
> You might be interested to know that Oz supports literally thousands of concurrent threads with no sweat.  D could learn some things from Oz.
>
> Mark
>
>