test_1_to_1_threads: fixup pthread hung by giving an array instead of a pointer
As we give a pointer arg to pthread_create, some thread's cnt will be set to 1
when we run into next loop, which may cause all the threads blocked by t_recv.
If we still want to use a pointer to avoid compile warning, then an array
should be a good choice.
Here I'd like to analyse the logic of function relay(). As Daniel said, this
test's purpose is communications across different threads, which would like:
Thread 1: send(sock_client), exit
Thread 2: recv(sock_server), send(sock_client), exit
...
Thread X-1: recv(sock_server), send(sock_client), exit
Thread X: recv(sock_server), exit
But this may cause test huang as we don't know the order of threads. e.g.
Thread 1: send(sock_client), exit
Thread 2: recv(sock_server), send(sock_client), exit
Thread X: recv(sock_server), exit
Thread 3: recv(sock_server), send(sock_client), hung
...
Thread X-1: recv(sock_server), send(sock_client), hung
If we receive first and put send at last. It may also cause hung like:
Thread X: send(sock_client), exit
Thread X-1: recv(sock_server), send(sock_client), exit
Thread 1: recv(sock_server), exit
Thread X-2: recv(sock_server), send(sock_client), hung
...
Thread 2: recv(sock_server), send(sock_client), hung
So, keep relay()'s logic like the following should be the best choice:
Thread 1: send(sock_client), exit
Thread 2: recv(sock_server), send(sock_client), exit
...
Thread X-1: recv(sock_server), send(sock_client), exit
Thread X: recv(sock_server), send(sock_client), exit
Then there will be no hung and we can keep communications across different
threads. Thus, we also don't need if (id == THREADS -1) now.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>