aio_read/7-1.c: fix race at exit

This testcase crashed in about 1/200 of runs on s390x system with 2 CPUs:

Core was generated by `./7-1.run-test'.
Program terminated with signal 11, Segmentation fault.
  #0  _dl_fini () at dl-fini.c:228
  228               if (l->l_init_called)
  (gdb) bt
  #0  _dl_fini () at dl-fini.c:228
  #1  0x000003fffd345c62 in __run_exit_handlers (status=<optimized out>, listp=0x3fffd4b4a78 <__exit_funcs>,
      run_list_atexit=run_list_atexit@entry=true) at exit.c:77
  #2  0x000003fffd345ca4 in __GI_exit (status=<optimized out>) at exit.c:99
  #3  0x000003fffd3294e6 in __libc_start_main (main=0x80000b18 <main>, argc=<optimized out>, ubp_av=0x3ffff970108,
      init=<optimized out>, fini=0x80000d4c <__libc_csu_fini>, rtld_fini=0x3fffd50821c <_dl_fini>, stack_end=0x3ffff970050)
      at libc-start.c:257
  #4  0x0000000080000a26 in _start ()
  (gdb) x/1x l
  0x9fd4f2918:    Cannot access memory at address 0x9fd4f2918

The crash was presumably caused by race, where variable defined in main()
got out of scope before operation started by aio_read() completed.

Patched version succesfully made 100000 iterations.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
1 file changed