How to get some comfort with threads?

View: New views
4 Messages — Rating Filter:   Alert me  

How to get some comfort with threads?

by uprinz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

I'd like to give some debug while system starts up. With dvice drivers
it is easy as the dev->dev_name gives an easy access to the devices name.

But with threads I don't know how to get the name of a thread.

I can do something like this:
if( NutThreadCreate("isAlive", isAlive, 0, 256))
     printf("Thread isAlive started\n");

if( NutThreadCreate("display", display, 0, 512))
     printf("Thread display started\n");

But I'd like to may be use a function to start up the thread and report
success or error by giving the name to the debug output.
Ah, and I don't like to search for an ID in a list or something like that.

And has someone any idea how to find out why a thread has died?

Any idea?

Best regards, Ulrich
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion

Re: How to get some comfort with threads?

by Adam Dybkowski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ulrich Prinz wrote:

> I'd like to give some debug while system starts up. With dvice drivers
> it is easy as the dev->dev_name gives an easy access to the devices name.
>
> But with threads I don't know how to get the name of a thread.

If you've got thread handle:

HANDLE th;

then it's easy to get the name of that thread:

const char *name = ((NUTTHREADINFO *) th)->td_name;

See for example the source code of system function NutThreadWake(),
everything will be clear. Also see NutDumpThreadList().

To do opposite conversion (map name to thread handle), just call
GetThreadByName().

--
Adam Dybkowski
                adybkows@...
                http://dybkowski.net/
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion

Re: How to get some comfort with threads?

by Nathan Moore-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If the only time you need it is for thread creation then why not do the
following?

HANDLE myThreadCreate(const char * name, thread_f * tf, void * arg, int
stack_sz) {    HANDLE th;
    th = NutThreadCreate(name, tf, arg, stack_sz);
    printf("Creating thread \"%s\" %s\n", name, th ? "succeeded" :
"failed");
    return th;
}

or if you need the name at some later time then do what Adam Dybkowski said.

Nathan
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion

Re: How to get some comfort with threads?

by Ole Reinhardt-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ulrich,

> I'd like to give some debug while system starts up. With dvice drivers
> it is easy as the dev->dev_name gives an easy access to the devices name.
>
> But with threads I don't know how to get the name of a thread.

Perhaps

runningThread->td_name

ist what you are looking for?

Bye,

Ole

--
 _____________________________________________________________
|                                                             |
| Embedded-IT                                                 |
|                                                             |
| Ole Reinhardt        Tel. / Fax:        +49 (0)271  7420433 |
| Luisenstraße 29      Mobil:             +49 (0)177  7420433 |
| 57076 Siegen         eMail:    ole.reinhardt@... |
| Germany              Web:         http://www.embedded-it.de |
|_____________________________________________________________|

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion