Will I run into an error if I create a pthread_create inside a pthread, which is created by the main function. If, I can then what all things I should take care of???
Important....:I am doing a socket programming, where I have opened 5 threads each on separate ports which are listening on ports, when ever I receive a message, I want to create a thread which takes the message and writes into a file using pwrite. So, I have a few questions, please can you help me???
If not then what is another solution of creating a thread inside a thread..??
Or will it give me a segmentation fault???
or will I run into some race conditions....
Yes. The typical problem, however, is that the work/threads are not constrained. Using the approach you have outlined, it's easy to spawn many threads and have an illogically high number of threads for the work which must be executed on a limited number of cores.
The Pthreads standard specifies concurrency; it allows parallelism to be at the option of system implementors. As a programmer, all you can do is define those tasks, or threads, that can occur concurrently.
A thread cannot join itself because a deadlock would occur and it is detected by the library. However, two threads may try to join each other. They will deadlock, but this situation is not detected by the library. The pthread_join subroutine also allows a thread to return information to another thread.
POSIX Threads, commonly known as pthreads, is an execution model that exists independently from a language, as well as a parallel execution model. It allows a program to control multiple different flows of work that overlap in time.
pthread_create
creates a new thread. Independently of where it is
called. And creating a new thread for a connection when listening on a
port is pretty much standard procedure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With