cpp: #include <omp.h>\n#include <stdio.h>\n#include <stdlib.h>\n\ntypedef struct {\n  int a, b;\n  omp_nest_lock_t lck;\n} pair;\n\nvoid incr_a(pair *p){\n  p->a += 1;\n}\n\nvoid incr_b(pair *p){\n  p->b += 1;\n}\n\n\nint main(int argc, char* argv[])\n{\n  pair p[1];\n  p->a = 0;\n  p->b = 0;\n  omp_init_nest_lock(&p->lck);\n\n  #pragma omp parallel sections\n  {\n    #pragma omp section\n    {\n      omp_set_nest_lock(&p->lck);\n      incr_b(p);\n      incr_a(p);\n      omp_unset_nest_lock(&p->lck);\n    }\n    #pragma omp section\n      incr_b(p);\n  }\n\n  omp_destroy_nest_lock(&p->lck);\n\n  printf("%d\n",p->b);\n  return 0;\n}\n
fortran: program DRB118_nestlock_orig_no\n    use omp_lib\n    use DRB118\n    implicit none\n\n    integer :: a, b\n\n    type(pair) :: p\n    p%a = 0\n    p%b = 0\n    call omp_init_nest_lock(p%lck);\n\n    !$omp parallel sections\n    !$omp section\n        call omp_set_nest_lock(p%lck)\n        call incr_b(p, a)\n        call incr_a(p, b)\n        call omp_unset_nest_lock(p%lck)\n\n    !$omp section\n        call incr_b(p, b);\n\n    !$omp end parallel sections\n\n    call omp_destroy_nest_lock(p%lck)\n\n    print*,p%b\n\nend program