我可以在主线程已经创建的 pthread 中创建 pthread 吗?
如果我在由 main 函数创建的 pthread 内创建 pthread_create ,是否会遇到错误。如果,我可以那么我应该照顾什么???
重要......:我正在做一个套接字编程,我在不同的端口上打开了5个线程,每个线程都在侦听端口,每当我收到一条消息时,我想创建一个线程来接收消息并将其写入使用 pwrite 文件。所以,我有几个问题,请你帮我解答一下???
如果不是,那么在线程内创建线程的另一种解决方案是什么......?
或者它会给我一个分段错误???
或者我会遇到一些竞争条件......
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....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pthread_create
创建一个新线程。与它所在的位置无关叫。并在监听时为连接创建一个新线程
端口几乎是标准程序。
pthread_create
creates a new thread. Independently of where it iscalled. And creating a new thread for a connection when listening on a
port is pretty much standard procedure.