Re: POSIX thread question




Mikko Rauhala wrote:
On 28 Aug 2006 14:15:21 -0700, Jack <junw2000@xxxxxxxxx> wrote:
Below is simple code of POSIX thread from a book:
[snip]
It creates 10 threads. My questions are:
1. The 10 threads share the same code. Do the 10 threads share both
main() and myThread(), or just myThread()?

Everything, though if myThread() exits, it will not return to main()
but terminate the thread. myThread _can_ for example call main() if
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
How to do
it?

After the following line is executed:
ret = pthread_create( &threadIds[i], NULL, myThread, NULL );

The ith thread is created, then the ith thread enters myThread()
function and remains there, right?

The following line is in main() function:
ret = pthread_mutex_destroy( &cntr_mutex );

Only the 10 threads' parent process can execute the above line and
destroy the cntr_mutex. The 10 threads can not destroy the cntr_mutex
since they do not execute main() function, right?

Thanks.

Jack

.