pthreads

pthreads

Post by Emanuel Harangu » Wed, 26 Jul 2000 04:00:00



I am running a program that is creating threads to ident ppl that are
connecting to that program. After the thread is done (I use
remove_thread(d->idthread);) the processes are there. Did I do something
wrong??? Shall I kill them within the main program (I thought remove_thread
is doing that)??

Anyway after the thread had indetified the user that is trying to connect
and it reaches the remove_thread the thread is still there... did I do
something wrong?? I have to add other things along remove_thread?? Like
what??

Hoping I didnt give ya headaches,
    Rygars is signing out

 
 
 

pthreads

Post by Kaz Kylhe » Wed, 26 Jul 2000 04:00:00



>I am running a program that is creating threads to ident ppl that are
>connecting to that program. After the thread is done (I use
>remove_thread(d->idthread);) the processes are there. Did I do something
>wrong??? Shall I kill them within the main program (I thought remove_thread
>is doing that)??

I have never heard of remove_thread. This function is not in the POSIX
threading interface.  To terminate a thread, you should have it return from the
top level function or call pthread_exit. Alternately, you can use cancellation:
have another thread call pthread_cancel on it.  Either way, if the thread is
joinable, some other thread must call pthread_join to collect it.

--
Any hyperlinks appearing in this article were inserted by the unscrupulous
operators of a Usenet-to-web gateway, without obtaining the proper permission
of the author, who does not endorse any of the linked-to products or services.

 
 
 

pthreads

Post by Remo Inverard » Tue, 01 Aug 2000 04:00:00


Quote:> Either way, if the thread is joinable, some other thread must
> call pthread_join to collect it.

You can also free the resources by calling pthread_detach (which
is probably *not* Posix compliant). The thread then frees its own
resources at termination.

Regards, Remo
______________________________________________________________________

[ http://public.toilet.ch/ ] "Ich dusche warm!" [ http://www.vbs.ch/ ]
______________________________________________________________________

 
 
 

1. a bug with pthread?

[public reply, as I think a few people might be interested in the results]

Without doing this, you will leak memory.  The pthread library MUST keep
information for each thread that exits until it has been reaped, unless it
is detached.  You will find the same "leaky" behavior exists on Solaris
(yes, I tried your program there).

Note also two other problems in your code.  First off
But the pointer that was passed in was on the *stack*.  You can't delete
something from the stack like that (on my glibc6 machine, this causes a core
dump).

Secondly (and much worse, IMHO), is the fact that you passed in a stack
structure.  It appears that you have omitted some code, so I will assume
what you do is fill in this stack structure with some data and then pass the
pointer in like you do.  But what if the following chain of events occur?

Fill in data for thread 1.
Call pthread_create for thread 1.
Fill in data for thread 2.
Call pthread_create for thread 2.
--now, thread 1 starts running-- (yes, this is a perfectly valid happening)
--now, thread 2 starts running-- (yes, this is a perfectly valid happening)

You will note that both threads get the data meants for thread 2.  Your
original idea of deleting clt is correct -- clt needs to be in the heap, not
on the stack.

Best of luck!
--randy

[code clipped]

2. nfs_acl on Solaris

3. pthreads and gdb

4. Network starting point

5. pthreads and the scheduler policies

6. Green & Red checks on exiting openwin

7. fcntl file locking and pthreads

8. cl?turer compte

9. apache module with pthread library linked crashes Apache 1.3.12 on RedHat Linux 6.2

10. Are pthreads' semaphores supposed to do this or is it a Linux bug?

11. pthreads, GDB, Segmantation fault

12. any luck with pthreads, anyone?

13. pthread and g++ problem