السلام عليكم
هل لينكس كيرنال وبالتحديد 2.6.x يدعم ال Multithreaded Application
اقرا معى هذا الاقتباس الذى هو من كتاب Advanced Linux Programming فى الفصل الرابع :-
4.5 GNU/Linux Thread Implementation
The implementation of POSIX threads on GNU/Linux differs from the thread imple-
mentation on many other UNIX-like systems in an important way: on GNU/Linux,
threads are implemented as processes.Whenever you call pthread_create to create a
new thread, Linux creates a new process that runs that thread. However, this process is
not the same as a process you would create with fork; in particular, it shares the same
address space and resources as the original process rather than receiving copies.
فمعنى ذلك ان الكيرنال لا يدعم ال Mutlithreading او يمكن القول بانه يتحايل على ذلك ليدعمها فاذا ما هو الفرق بين دعمها حقيقايا وان ال process تقسم الى threads ويقسم وقتها على هذه ال threads وبين تلك الحالة التى اختلط فيها مفهوم ال process بمفهوم ال thread واصبح كل منهما يساوى الاخر فى المعنى لدى النظام
وايضا اود ان اعرف ما هى فائدة kthread process والتى تاخذ pid 2
ملحوظة جربت مثال كان مكتوب فى الكتاب لكى اتاكد من ان النظام يعطر pid لل main تختلف عن ال pid الخاصة بال process التى تعيش داخلها ال thread وهذا هو الكود
- #include <pthread.h>
- #include <stdio.h>
- #include <unistd.h>
- void* thread_function (void* arg)
- {
- fprintf (stderr, "child thread pid is %dn", (int) getpid ());
- /* Spin forever. */
- while (1);
- return NULL;
- }
- int main ()
- {
- pthread_t thread;
- fprintf (stderr, "main thread pid is %dn", (int) getpid ());
- pthread_create (&thread, NULL, &thread_function, NULL);
- /* Spin forever. */
- while (1);
- return 0;
- }
لتجريب عمل compile لهذا الكود من خلال الامر :-
- gcc -o th main.c -lpthread
- ./th
وللاسف كان الخرج
- main thread pid is 6258
- child thread pid is 6258
فما معنى ذلك ???
اطيب المنى :)
