作者:再见傻瓜傻瓜_299 | 来源:互联网 | 2023-09-11 18:38
Iwanttocreateaprocessrunningunderlinuxthatcreatesmultiplethreads,eachthreadwritingth
I want to create a process running under linux that creates multiple threads, each thread writing their own data out to a receiving process over a UDP socket connection. For sizing, say I need to have up to one hundred of these threads all running simultaneously with threads coming and going.
我想创建一个在linux下运行的进程,该进程创建多个线程,每个线程通过UDP套接字连接将自己的数据写入一个接收进程。对于大小调整,假设我需要有多达100个这样的线程同时运行,同时有线程来来去去。
Is it better to have each thread open up it's own socket to the same destination using the same UDP port number when the thread is created (thus needing 100 separate file descriptors) or to open the socket one time in the main thread and pass that file descriptor to each of the threads so it each uses the same socket? Each thread will be generating about 20 packets per second, each packet roughly 800 bytes in length. There is no synchronization between threads.
最好是每个线程打开它自己的套接字到相同的目的地使用相同的UDP端口号创建线程时(因此需要100个独立的文件描述符)或一次打开套接字在主线程和文件描述符传递给每一个线程,所以每个使用相同的套接字?每个线程将每秒生成大约20个数据包,每个数据包大约800字节。线程之间没有同步。
4 个解决方案