Re: Re: A question about _thread_ of Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Hi, I did a quick look at the code of the NPTL. I found that the
> pthread_self does not return the tid but the address of the struct
> pthread which is allocated in the stack (at least on i386 and possibly
> on other Arch too). Struct pthread contains various information used
> by the pthreaded calls. It created in the stack during pthread
> creation. pthread_self just finds the structure from stack and return
> its address.
Yes! It is right. I "strace"d the _pid_ file compiled from pid.c, I get
the result as follows(just a snapshot).

clone(child_stack=0xb7f7d4d4,
    flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|
        CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|
        CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
    parent_tidptr=0xb7f7dbe8,
    {entry_number:6, base_addr:0xb7f7dba0, limit:1048575,
         seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1,
         seg_not_present:0, useable:1},
   child_tidptr=0xb7f7dbe8) = 21945

clone(child_stack=0xb757c4d4,
     flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|
         CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|
         CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
     parent_tidptr=0xb757cbe8,
     {entry_number:6, base_addr:0xb757cba0, limit:1048575,
         seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1,
         seg_not_present:0, useable:1}, child_tidptr=0xb757cbe8) = 21946

futex(0xb7f7dbe8, FUTEX_WAIT, 21945, NULL
     In the thread 0:posix tid 3086474144
     In the thread 0:pid 21944
     In the thread 0:tid 21945) = 0

futex(0xb757cbe8, FUTEX_WAIT, 21946, NULL
     In the thread 1:posix tid 3075984288
     In the thread 1:pid 21944
     In the thread 1:tid 21946) = 0
 
As we see, the blue number == the blue number,
while the red number == the red number
 
Best Regards,
Cheng




 

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux