execution order of thread ??

Hi.

According to the QNX document, each thread can run concurrently, or run
sequently based on the priority.
Then, what is the meaning of order of the thread in main()??
I mean…for example

main() {


sub0() // get data from serial port;

sub1();

sub2();

}

In normal C program, I can assume that sub1 is executed first and then
sub2() is executed next.
How about in QNX ??
Thanks!

Pasus

Thanks for answer.

I understand that sub0(), sub1() and sub2() are threads (i.e. subroutine is
thread).
Isn’t it correct?
If they are thread, what is the execution order of them? always topdown, not
depending on priority?

I am really a beginner of real-time program (and QNX). :slight_smile:
Thanks!

Pasus

I think you’re confusing execution order with scheduling order. The
execution of a thread is always top->down (with the exception of using
goto
or looping > :slight_smile: > ). Scheduling of the threads (ie. which one is running at
any
instance in time) can be changed based on priority.

-Adam

Pasus <pasus@mail.nu> wrote:

Thanks for answer.

I understand that sub0(), sub1() and sub2() are threads (i.e. subroutine is
thread).
Isn’t it correct?

No, that is not correct. sub0(), sub1(), and sub2() are subroutine calls within
a thread. That is to say, in your example, the thread that is executing main()
visits sub0(), then sub1(), and then sub2(). Your example program only has
one thread. If you wanted to make your program have multiple threads, then you
could do something like:

main ()
{
pthread_create (NULL, NULL, sub0, NULL);
pthread_create (NULL, NULL, sub1, NULL);
pthread_create (NULL, NULL, sub2, NULL);
}

This now means that the thread that’s running main() explicitly calls pthread_create()
to create three new threads, which will begin executing at sub0(), sub1(), and
sub2(). NOW you have a program with 4 threads.

If they are thread, what is the execution order of them? always topdown, not
depending on priority?

In your code example they were not threads, hence execution order was as specified
by the language (i.e., one statement after another, with looping, testing, etc.
like Adam said).

In my code example, things get a little bit more complicated, because you now have
four threads running. (Ignore the fact that when it falls off the end of main() the
entire process dies for just now :slight_smile:).

The main() thread starts. It executes the next statement, that tells the kernel to
start a thread for it at sub0(). Since “pthread_create()” is not a blocking call,
the currently running thread continues. It hits the next statement, which says to
create another thread, this time starting at sub1(), and so on.

I am really a beginner of real-time program (and QNX). > :slight_smile:

There are a number of books out there :slight_smile: but to answer this question a book
on threads would probably be best, as well as a general C/UNIX programming book.

Cheers,
-RK

Thanks!

Pasus

I think you’re confusing execution order with scheduling order. The
execution of a thread is always top->down (with the exception of using
goto
or looping > :slight_smile: > ). Scheduling of the threads (ie. which one is running at
any
instance in time) can be changed based on priority.

-Adam


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Consulting and Training at www.parse.com
Email my initials at parse dot com.

<nospam93@parse.com> wrote in message news:9rslpu$37m$1@inn.qnx.com

Pasus <> pasus@mail.nu> > wrote:
Thanks for answer.

I understand that sub0(), sub1() and sub2() are threads (i.e. subroutine
is
thread).
Isn’t it correct?

No, that is not correct. sub0(), sub1(), and sub2() are subroutine calls
within
a thread. That is to say, in your example, the thread that is executing
main()
visits sub0(), then sub1(), and then sub2(). Your example program only
has
one thread. If you wanted to make your program have multiple threads,
then you
could do something like:

main ()
{
pthread_create (NULL, NULL, sub0, NULL);
pthread_create (NULL, NULL, sub1, NULL);
pthread_create (NULL, NULL, sub2, NULL);
}

This now means that the thread that’s running main() explicitly calls
pthread_create()
to create three new threads, which will begin executing at sub0(),
sub1(), and
sub2(). NOW you have a program with 4 threads.

If they are thread, what is the execution order of them? always topdown,
not
depending on priority?

In your code example they were not threads, hence execution order was as
specified
by the language (i.e., one statement after another, with looping, testing,
etc.
like Adam said).

In my code example, things get a little bit more complicated, because
you now have
four threads running. (Ignore the fact that when it falls off the end of
main() the
entire process dies for just now > :slight_smile:> ).

The main() thread starts. It executes the next statement, that tells the
kernel to
start a thread for it at sub0(). Since “pthread_create()” is not a
blocking call,
the currently running thread continues. It hits the next statement, which
says to
create another thread, this time starting at sub1(), and so on.

I am really a beginner of real-time program (and QNX). > :slight_smile:

There are a number of books out there > :slight_smile: > but to answer this question a
book
on threads would probably be best, as well as a general C/UNIX programming
book.

Cheers,
-RK

Thanks!

Pasus

I think you’re confusing execution order with scheduling order. The
execution of a thread is always top->down (with the exception of using
goto
or looping > :slight_smile: > ). Scheduling of the threads (ie. which one is running
at
any
instance in time) can be changed based on priority.

-Adam




\

Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Consulting and Training at > www.parse.com
Email my initials at parse dot com.

It’s my honor to get answer from you!
Actually, I stopped by bookstore last week to buy your book “Getting started
with QNX Nutrino…”, but was told that I should wait for 4-5 weeks. So,
now I am waiting for that bookstore to get it.
I’ll see you soon on the book.
Thanks.

Pasus

“Pasus” <pasus@mail.nu> wrote in message news:9rsacs$q50$1@inn.qnx.com

According to the QNX document, each thread can run concurrently, or run
sequently based on the priority.
Then, what is the meaning of order of the thread in main()??

I think you’re confusing execution order with scheduling order. The
execution of a thread is always top->down (with the exception of using goto
or looping :slight_smile: ). Scheduling of the threads (ie. which one is running at any
instance in time) can be changed based on priority.

-Adam