test_1_to_1_threads: fixup pthread hung by giving an array instead of a pointer
commita2765e638f4f0b5c49b836927c4d670c197b58a6
authorHangbin Liu <liuhangbin@gmail.com>
Tue, 26 Feb 2013 02:03:58 +0000 (26 10:03 +0800)
committerDaniel Borkmann <dborkman@redhat.com>
Wed, 6 Mar 2013 15:16:07 +0000 (6 16:16 +0100)
treedc596931ffdf788d564b25aaca37627224729ccd
parent2266bb3ea3f7f334947c5382b6a9db75a1a2e1b8
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>
src/func_tests/test_1_to_1_threads.c