On Sat, Oct 13, 2012 at 7:09 AM, Volker Armin Hemmann
<[email protected]> wrote:
> Am Samstag, 13. Oktober 2012, 14:15:50 schrieb Timur Aydin:
>> On 10/13/12 04:11, Mark Knecht wrote:
>> > Take look here. The answer is, I think, not necessarily.
>> >
>> > http://www.makelinux.net/alp/032
>>
>> Hello Mark,
>>
>> Thank you for the link to an excellent book. However, it seems the book
>> is talking about linuxthreads by Xavier Leroy, not nptl. I am well aware
>> that linuxthreads uses LWP's to implement threads and as a result, each
>> thread has a separate, unique pid.
>>
>> I did a few more tests using gdb and my simple app. I am seeing the
>> SIG32 signal and the lack of the manager threads. So everything hints
>> that I am indeed using nptl, but the separate process id's still doesn't
>> make sense...
>
> or you made a mistake somewhere in your app.
We can only know seeing the code. Timur, this is the little test I
made which creates 5 threads and runs them for 1 minute. In my case,
`ps x` shows only 1 PID, care to give it a try?
----------------------
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int keep_running;
static void*
my_thread(void* data)
{
int id = *((int*)data);
int count = 0;
sleep(id);
printf("Thread %d beginning.\n", count++);
while (keep_running) {
printf("Thread %d: %d.\n", id, count++);
sleep(1);
}
printf("Thread %d exiting.\n", count++);
}
int
main(int argc, char* argv[])
{
keep_running = 1;
pthread_t a, b, c, d, e;
int* arr[] = { NULL, NULL, NULL, NULL, NULL };
int i;
for (i = 0; i < 5; i++) {
arr[i] = malloc(sizeof(int));
*arr[i] = i;
}
pthread_create(&a, NULL, my_thread, arr[0]);
pthread_create(&b, NULL, my_thread, arr[1]);
pthread_create(&c, NULL, my_thread, arr[2]);
pthread_create(&d, NULL, my_thread, arr[3]);
pthread_create(&e, NULL, my_thread, arr[4]);
sleep(60);
pthread_mutex_lock(&mutex);
keep_running = 0;
pthread_mutex_unlock(&mutex);
for (i = 0; i < 5; i++)
free(arr[i]);
}
----------------------
Regards.
--
Canek Peláez Valdés
Posgrado en Ciencia e Ingeniería de la Computación
Universidad Nacional Autónoma de México