| 1 |
! { dg-do run } |
| 2 |
! Multiple threads call open/write/read/close in concurrency with different unit number, |
| 3 |
! threads can acquire read lock concurrently, to find unit from cache or unit list very frequently, |
| 4 |
! if not found, threads will acquire the write lock exclusively to insert unit to cache and unit list. |
| 5 |
! This test case is used to stress both the read and write lock when access unit cache and list. |
| 6 |
program main |
| 7 |
use omp_lib |
| 8 |
implicit none |
| 9 |
integer:: unit_number, v1, v2, i |
| 10 |
character(11) :: file_name |
| 11 |
character(3) :: async = "no" |
| 12 |
!$omp parallel private (unit_number, v1, v2, file_name, async, i) |
| 13 |
do i = 0, 100 |
| 14 |
unit_number = 10 + omp_get_thread_num () |
| 15 |
write (file_name, "(I3, A)") unit_number, "_tst.dat" |
| 16 |
file_name = adjustl(file_name) |
| 17 |
open (unit_number, file=file_name, asynchronous="yes") |
| 18 |
! call inquire with file parameter to test find_file in unix.c |
| 19 |
inquire (file=file_name, asynchronous=async) |
| 20 |
if (async /= "YES") stop 1 |
| 21 |
write (unit_number, *, asynchronous="yes") unit_number |
| 22 |
write (unit_number, *, asynchronous="yes") unit_number + 1 |
| 23 |
close(unit_number) |
| 24 |
|
| 25 |
open (unit_number, file = file_name, asynchronous="yes") |
| 26 |
read (unit_number, *, asynchronous="yes") v1 |
| 27 |
read (unit_number, *, asynchronous="yes") v2 |
| 28 |
wait (unit_number) |
| 29 |
if ((v1 /= unit_number) .or. (v2 /= unit_number + 1)) stop 2 |
| 30 |
close(unit_number, status="delete") |
| 31 |
end do |
| 32 |
!$omp end parallel |
| 33 |
end program |