1 |
On Sat, Oct 13, 2012 at 7:09 AM, Volker Armin Hemmann |
2 |
<volkerarmin@××××××××××.com> wrote: |
3 |
> Am Samstag, 13. Oktober 2012, 14:15:50 schrieb Timur Aydin: |
4 |
>> On 10/13/12 04:11, Mark Knecht wrote: |
5 |
>> > Take look here. The answer is, I think, not necessarily. |
6 |
>> > |
7 |
>> > http://www.makelinux.net/alp/032 |
8 |
>> |
9 |
>> Hello Mark, |
10 |
>> |
11 |
>> Thank you for the link to an excellent book. However, it seems the book |
12 |
>> is talking about linuxthreads by Xavier Leroy, not nptl. I am well aware |
13 |
>> that linuxthreads uses LWP's to implement threads and as a result, each |
14 |
>> thread has a separate, unique pid. |
15 |
>> |
16 |
>> I did a few more tests using gdb and my simple app. I am seeing the |
17 |
>> SIG32 signal and the lack of the manager threads. So everything hints |
18 |
>> that I am indeed using nptl, but the separate process id's still doesn't |
19 |
>> make sense... |
20 |
> |
21 |
> or you made a mistake somewhere in your app. |
22 |
|
23 |
We can only know seeing the code. Timur, this is the little test I |
24 |
made which creates 5 threads and runs them for 1 minute. In my case, |
25 |
`ps x` shows only 1 PID, care to give it a try? |
26 |
|
27 |
---------------------- |
28 |
#include <pthread.h> |
29 |
#include <unistd.h> |
30 |
#include <stdlib.h> |
31 |
#include <stdio.h> |
32 |
|
33 |
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
34 |
static int keep_running; |
35 |
|
36 |
static void* |
37 |
my_thread(void* data) |
38 |
{ |
39 |
int id = *((int*)data); |
40 |
int count = 0; |
41 |
|
42 |
sleep(id); |
43 |
printf("Thread %d beginning.\n", count++); |
44 |
|
45 |
while (keep_running) { |
46 |
printf("Thread %d: %d.\n", id, count++); |
47 |
sleep(1); |
48 |
} |
49 |
printf("Thread %d exiting.\n", count++); |
50 |
} |
51 |
|
52 |
int |
53 |
main(int argc, char* argv[]) |
54 |
{ |
55 |
keep_running = 1; |
56 |
pthread_t a, b, c, d, e; |
57 |
int* arr[] = { NULL, NULL, NULL, NULL, NULL }; |
58 |
int i; |
59 |
for (i = 0; i < 5; i++) { |
60 |
arr[i] = malloc(sizeof(int)); |
61 |
*arr[i] = i; |
62 |
} |
63 |
pthread_create(&a, NULL, my_thread, arr[0]); |
64 |
pthread_create(&b, NULL, my_thread, arr[1]); |
65 |
pthread_create(&c, NULL, my_thread, arr[2]); |
66 |
pthread_create(&d, NULL, my_thread, arr[3]); |
67 |
pthread_create(&e, NULL, my_thread, arr[4]); |
68 |
sleep(60); |
69 |
pthread_mutex_lock(&mutex); |
70 |
keep_running = 0; |
71 |
pthread_mutex_unlock(&mutex); |
72 |
for (i = 0; i < 5; i++) |
73 |
free(arr[i]); |
74 |
} |
75 |
---------------------- |
76 |
|
77 |
Regards. |
78 |
-- |
79 |
Canek Peláez Valdés |
80 |
Posgrado en Ciencia e Ingeniería de la Computación |
81 |
Universidad Nacional Autónoma de México |