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 ?
    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

Reply via email to