RE: User Level Threads implementation by Linux kernel

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

 



Hi Ravi,

 

Find my inline responses.

 

From: kernelnewbies-bounce@xxxxxxxxxxxx [mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of ravikumar
Sent: Tuesday, March 02, 2010 4:20 PM
To: Kernel Newbies
Subject: User Level Threads implementation by Linux kernel

 

Hi all,

Currently I'm going through book 'development of Linux kernel' by Robert Love.
In the chapter 'Process  Management' I read below sentence
"Linux has a unique implementation of threads: It does not differentiate between threads and processes. To Linux, a thread is just a special kind of process."
In kernel everything is a just task represented by  task_struct

And from some other sources I understand that there is a one-one mapping between threads created by library API and kernel threads.

Now my questions are :
1. I have Program  and I've created two threads say T1 and T2 using Posix Thread Library. see below
    void* function2()
{
   while(1)
   {
        printf("I'm Thread 2\n");
        sleep(1);
   }
}
void* function1()
{
        printf("I'm Thread 1\n");
        char buf[1024];
        read(1,buf,1023);             // Thread 1 will block here
}
int main(int argc,char *argv[])
{

 pthread_t pid1,pid2;
 pthread_create(&pid1,NULL,function1,NULL);
 pthread_create(&pid2,NULL,function2,NULL);
 while(1)
 {
        printf("I'm Main Thread\n");
        sleep(1);
 }
}

  
According my understanding there will be three tasks will be created in the kernel after I ran this program. One is for main process say P and other two for T1 and T2.
And T1 & T2 share the address space of P. Is my understanding is correct?


2.Regarding the scheduling.
    Upon running the above program , the output is:
    I'm Main Thread
    I'm Thread 1
    I'm Thread 2
    I'm Main Thread
    I'm Thread 2
    I'm Main Thread
    I'm Thread 2
    I'm Main Thread
    I'm Thread 2
    I'm Main Thread
    I'm Thread 2
    Though Thread  1 is blocked Main Thread  and Thread 2 are still running.
     That means different user-level threads are scheduled by kernel separately.Is this correct ?

 

As per my understanding, yes, for every user thread kernel creates a separate task_struct. In kernel, scheduling entity is task_struct, so each user thread will be scheduled independently and will be given its own time slice for execution. Scheduling will only happen on the task_struct in run queue (in this case only main thread and thread 2 , not thread 1).


     If this is correct how time slices will be allocated?

   Do please some body clarify my questions  and also provide some good links as references

   Thank you all

Regards,
Ravikumar


DISCLAIMER: 
----------------------------------------------------------------------------------------------------------------------- 
The contents of this e-mail and any attachment(s) are confidential and
intended 
for the named recipient(s) only.  
It shall not attach any liability on the originator or NECHCL or its 
affiliates. Any views or opinions presented in  
this email are solely those of the author and may not necessarily reflect the 
opinions of NECHCL or its affiliates.  
Any form of reproduction, dissemination, copying, disclosure, modification, 
distribution and / or publication of  
this message without the prior written consent of the author of this e-mail is 
strictly prohibited. If you have  
received this email in error please delete it and notify the sender 
immediately. . 
-----------------------------------------------------------------------------------------------------------------------

[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