Hi Peter,
of course you can use the former explained functionality of the cpu-session interface to obtain the thread id of a newly created one, as all threads are created in fact via the cpu-session interface. But as long as you do not 'hand code' the whole thread creation process, but use the 'Thread_base' class resp. your own derived form of it, there is a handier way to do this. The 'Genode::Thread_base' class and its derivates contain a 'Native_thread' member. This is the platform-specific representation of the thread within the generic this class. So you might get the thread id by the following snippet:
// Assuming your thread object is called 'th' PDBG("thread id: %lx", th.tid().l4id.raw);
The value of 'tid()' will be valid only, after the thread to be created, already executed its bootstrapping code (at least under OKL4 this bootstrapping code copies the thread id to the thread object). So if you want to print out the thread id immediately after you created the thread, you should synchronize the thread creator's context with the new thread's context e.g. by using a lock:
// creation context My_thread_class th("thread_xy"); th.start(); _startup_lock.lock(); PDBG("id of new the new thread: %lx", th.tid().l4id.raw);
...
// entry code of 'thread_xy' _startup_lock.unlock();
I hope this is what you were looking for.
Regards Stefan
On Wednesday, 20. January 2010 12:11:41 Peter Nguyen wrote:
I was more wondering how to get the numerical ID of the thread after i've created one. Is it possible to obtain that at all?
Peter
On 19/01/2010, at 8:06 PM, Stefan Kalkowski wrote:
Hi Peter,
On Tuesday, 19. January 2010 06:30:22 Peter Nguyen wrote:
Hi,
So I've done some more messing around with genode (running on top of OKL4), more specifically creating some threads, and testing the functionality in general. I'm wondering how i can go about obtaining the thread's ID and printing it out. I've noticed that there are functions that are within the Thread class that can get me a Native_thread_id, but currently I can't seem to do much with it.
Speaking of the native thread, is that type related to L4? Can I actually get a numerical value for that ID?
that's right, 'Native_thread_id' is the platform-specific thread representation, so in the OKL4-case it is 'L4_ThreadId_t' indeed. The kernel-specific thread id in Genode/OKL4 is a member of 'Thread_state' a thread property, that can be obtained via the cpu-session interface.
Although, it is recommended to use only generic Genode abstractions to stay platform-independent, if you've to deal with the kernel-api directly, you might use the cpu-session interface to gain some platform-specific thread data within 'Thread_state'.
Here is some example code, printing all OKL4 thread IDs of one cpu- session:
int i; Genode::Thread_state state; Genode::Thread_capability tcap = Genode::env()->cpu_session()-
first();
while(tcap.valid()) { Genode::env()->cpu_session()->state(tcap, &state); PDBG("tid of thread no. %d is %lx", i, state.tid.raw); tcap = Genode::env()->cpu_session()->next(tcap); ++i; }
Thereby, the order of the threads given by cpu-session's iterator isn't necessarily the order of the thread's creation time!
Regards Stefan
Peter
--- --- Throughout its 18-year history, RSA Conference consistently attracts the world's best and brightest in the field, creating opportunities for Conference attendees to learn about information security's most important issues through interactions with peers, luminaries and emerging and established companies. http://p.sf.net/sfu/rsaconf-dev2dev _______________________________________________ Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
-- Stefan Kalkowski Genode Labs Developer http://genode-labs.com
----- Throughout its 18-year history, RSA Conference consistently attracts the world's best and brightest in the field, creating opportunities for Conference attendees to learn about information security's most important issues through interactions with peers, luminaries and emerging and established companies. http://p.sf.net/sfu/rsaconf-dev2dev _______________________________________________ Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
--- Throughout its 18-year history, RSA Conference consistently attracts the world's best and brightest in the field, creating opportunities for Conference attendees to learn about information security's most important issues through interactions with peers, luminaries and emerging and established companies. http://p.sf.net/sfu/rsaconf-dev2dev _______________________________________________ Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main