Topic: Appgraphics mutex
Can you give me a little more explanation how mutexes works with Appgraphics? 
I wish keep main program computing and comunicate by shared variables with interface. To protect them I create mutex by call of createmutex() . Inside the main program I'm able to lock it and unlock it. But if I try to do same inside callback procedure konec I never get lock. For now I just comment out few lines of code but it is unsatisfactory. 
 Could you help me, please?
  Thanks 
     Petr
module apptools
    use appgraphics
    integer :: myscreen
    integer :: menuroot_id !> root menu id
    integer :: menu_close
    integer :: menu_actions
    integer :: menu_help
    integer :: mclose_act
    integer :: mut_main
    
    logical :: skoncit
contains
  subroutine konec()
    print *, "koncime", mut_main
    !if ( lockmutex(mut_main, -1) ) then
       skoncit = .true.
       print *, "oznaceno"
       !call unlockmutex(mut_main)
    !end if
  end subroutine konec
end module apptools
program main
use appgraphics
use apptools
implicit none
    real(16) :: s,i
    integer :: inisizex, inisizey
    character(65) :: repstr
    integer :: cnt
    
    inisizex = 800 
    inisizey = 600
    skoncit = .false.
    mut_main = createmutex()
    print *, mut_main
    print *, lockmutex(mut_main)
    call unlockmutex(mut_main)
    myscreen = initwindow(inisizex, inisizey, closeflag=.false.)
    menuroot_id = addmenu("")
    print *, menuroot_id
    menu_actions = addmenu("Activity",menuroot_id)
    print *, menu_actions
    menu_close   = addmenu("Konec", menuroot_id)
    print *, menu_close
    menu_help = addmenu("Napoveda", menuroot_id)
    print *, menu_help
    mclose_act = addmenuitem("Ukoncit program,",menu_close,konec)
    
    !call loop()
    s = 0
    i = 0
    cnt = 0
   mainloop : do
      i = i + 1
      s = s + 1/i
      cnt = cnt + 1
      !print *, i,s
      if ( isvalidwindow(myscreen) .and. (cnt == 10000) ) then 
        cnt = 0
        write(repstr,"(f15.0,2f25.17)") i,s,s-log(i)
        call outtextxy(50,200,repstr);
        if ( lockmutex(mut_main) ) then
          if ( skoncit ) then
            print *, "jdu koncit"
            call unlockmutex(mut_main)
            exit mainloop
          end if
        end if
      end if
    end do mainloop
    print *, "Chci zavrit okno5"
    call closewindow(myscreen)
end program main