signal_action does not have effect if S_*_FORCE is used

Issue #57 resolved
Darío Cutillas Carrillo created an issue

I am not sure if it is a bug, but calling signal_action with S_IGN has no effect if we make use of "FORCE" signals.

The following will not let my_process run if you replace S_FREEZE by S_FREEZE_FORCE. It works however if you use S_FREEZE.

Begin
        ...
        pid = my_process();
        wait_process (pid);
        ...
End

Process wait_process ( int pid )
Begin
    signal_action ( pid, S_FREEZE, S_IGN );
    signal ( ALL_PROCESS, S_FREEZE);

    Repeat
        Frame;
    Until ( get_status ( pid ) == 0 )

    signal ( ALL_PROCESS, S_WAKEUP );
End

Comments (11)

  1. Benjamin Hoffmann

    It works well with my example :

    global
        int my_process_pid;
    end 
    
    begin       
    
        my_process_pid = my_process();
    
        // signal(all_process, s_freeze_force);
        signal(all_process, s_freeze);
    
        while(!key(_esc) and !exit_status)  
            frame;
        end
        exit();
    end
    
    
    process my_process()
    begin
        signal_action(id, s_freeze, s_ign);
        loop
            say("I'm " + id + " and I'm alive !");
        frame;
        end
    end
    
  2. Joseba Echevarria García repo owner

    Thanks for reporting, Dario.

    Could you please post a complete working example? (imports included). This way we'll be able to trace the issue back.

  3. Benjamin Hoffmann

    The problem comes from the repeat loop. The "signal(ALL_PROCESS, S_WAKEUP);" line is interpreted without waiting for your loop. This code works :

    import "mod_video"
    import "mod_key"
    import "mod_text"
    import "mod_sound"
    import "mod_wm"
    import "mod_map"
    import "mod_draw"
    import "mod_say"
    import "mod_file"
    import "mod_text"
    import "mod_multi"
    import "mod_mouse"
    import "mod_proc"
    import "mod_screen"
    import "mod_rand"
    import "mod_grproc"
    import "mod_math"
    import "mod_scroll" 
    import "mod_effects"
    import "mod_timers"
    import "mod_mem"
    import "mod_multi"
    
    global
        int my_process_pid;
    end 
    
    begin       
    
        my_process_pid = my_process();
        wait_process(my_process_pid);
    
        while(!key(_esc) && !exit_status)   
            frame;
        end
        exit();
    end
    
    
    process my_process()
    begin
        loop
            say("I'm " + id + " and I'm alive !");
        frame;
        end
    end
    
    process wait_process(int pid)
    begin
        signal_action(pid, s_freeze, s_ign);
        signal(all_process, s_freeze_force);
    
        while(get_status(pid) != 0 && !key(_esc))
            frame;
        end
    
        signal(all_process, s_wakeup);
    end
    

    (Sorry for including all the modules :p )

  4. Darío Cutillas Carrillo reporter

    Thank you Benjamin for your code example, however I did not understand what you meant with the "the problem is the repeat loop", perhaps I am missing something super easy but cannot see it right now...

    Here it comes an example:

    #!
    
    import "mod_video"
    import "mod_say"
    import "mod_proc"
    import "mod_key"
    
    private
        int my_pid;
    end
    begin
    
        set_mode ( 320, 240 );
        my_pid = my_process ();
        wait_process ( my_pid );
    
        say ( "This should show up after my_process finishes (press ESC to exit)" );
    
        while ( key ( _esc ) == 0 )
            frame;
        end
    
    end
    
    process my_process ()
    begin
        repeat
            say ( "In a loop (press A to stop)" );
            frame;
        until ( key ( _A ) )
    end
    
    process wait_process ( int pid )
    begin
        signal_action ( pid, s_freeze, s_ign );
        signal ( all_process, s_freeze);
    
        say ( get_status ( pid ) );
    
        while ( get_status ( pid ) != 0 )
            frame;
        end
    
        signal ( all_process, s_wakeup_force);
    end
    

    Change signal ( all_process, s_freeze); by signal(all_process, s_freeze_force) and you will see that say ( get_status (pid) ) is 4, and I do not understand if it is supposed to be like that because what I expect is that when I set signal_action, pid is going to ignore any S_FREEZE command.

    I also tried: * signal_action(pid, s_freeze_force, s_ign) * setting a frame; after signal_action

    Perhaps my understanding of the signal function is not complete so please educate me if so :)

  5. Darío Cutillas Carrillo reporter

    Benjamin, what I would expect in your code is to repeatedly get "I'm " + id + " and I'm alive !" and I can only see it once! That is the reason to use signal_action on pid, so as the process ignores the "Freezing". Or am I wrong?

  6. Benjamin Hoffmann

    I think your example is working well, I don't see any bug. When you set signal_action(pid, s_freeze, s_ign), the process will ignore the s_freeze signal. But the s_freeze_force will not be ignored. I think that the force signals can never be ignored. This behavior seems to be correct to me.

  7. Darío Cutillas Carrillo reporter

    If forced signals are never to be ignored then there is of course no problem. For me it made sense that forced signals could be ignored as I understand a Force signal as something that is to be sent "immediately" without waiting for the next frame; But perhaps this understanding is wrong.

    So the question is: Are Forced signals never to be ignored?

  8. Benjamin Hoffmann

    I'm agree with you.

    I did not understand your first question at first, but now its clear ^^.

    In my opinion, PixTudio must have a signal that can affect all the processes whatever theire status.

    It can be usefull when you want to freeze all the processes when your application is not focused on Android, and unfreeze them when the application got the focus back.

  9. Log in to comment