2016-12-21 1 views
3

B이라는 작업을 호출하는 작업이 A입니다.
일부 파인트 작업에서 B은 종료되었지만 작업 A은이를 알지 못하고 호출은 이제 작업 B을 종료합니다.
작업 B이 작업 A에서 호출을 종료하므로 작업 A을 종료합니다.Ada에서 작업이 종료되는지 확인하는 방법

B 작업이 A 작업에서 종료되었는지 어떻게 확인할 수 있습니까?

중요한 경우 GNAT Programming Studio를 사용하고 있습니다.
종료하기 전에 B으로 설정 한 전역 변수를 만들 수 있지만 A에서 B 상태를 찾는 것이 좋습니다. 당신은 B'Terminated를 확인할 수 있습니다

답변

5

, 다음의 예는 일련의 작업이 완료되면 주요 작업이 판단 할 수 있도록 '종료 속성을 사용 RM 9.9

if not B'Terminated then 
    -- do something 
end if; 
0

참조하십시오.

------------------------------------------------------------------ 
-- Parallel Array Filling -- 
------------------------------------------------------------------ 
with Ada.Text_IO; use Ada.Text_IO; 
with Ada.Numerics.Discrete_Random; 
with Ada.Calendar; use Ada.Calendar; 

procedure Array_Fill is 
    Start_Time : Time := Clock; 
    Num_Tasks : constant := 8; 
    Slice_Size : constant Natural := 8_388_608; 
    Max_Size : constant Natural := Num_Tasks * Slice_Size -1; 
    subtype Values is Natural range 0..10_000; 

    type Big_Array is array(Natural range 0..Max_Size) of Integer; 
    type Big_Access is access Big_Array; 

    -- Instantiate the generic package Ada.Numerics.Discrete_Random 
    -- to produce random numbers in the range of the subtype Values 
    -- defined above 
    package Rand_Nums is new Ada.Numerics.Discrete_Random(Values); 
    use Rand_Nums; 

    -- dynamically allocate the integer array, initializing all array 
    -- elements to the lowest valid value for type Integer 
    The_Array : Big_Access := new Big_Array'(Others => Integer'First); 

    task type Filler is 
     -- Set_Low is a synchronization point between the main task and 
     -- an instance of the task type Filler. This point allows the main 
     -- task to send an integer value >= 0 directly to the Filler task 
     Entry Set_Low(Item : in Natural); 
    end Filler; 

    task body Filler is 
     Id   : Natural; 
     Low_Index : Natural; 
     High_Index : Natural; 
     Seed  : Generator; 
    begin 
     Reset(Seed); 

     -- the Filler task waits for the main task to send a value to the 
     -- entry Set_Low. 
     accept Set_Low(Item : in Natural) do 
     Id := Item; 
     end Set_Low; 

     Low_Index := Id * Slice_Size; 
     High_Index := Low_Index + (Slice_Size - 1); 

     for I in Low_Index..High_Index loop 
     The_Array(I) := Random(Seed); 
     end loop; 
    end Filler; 

    -- create an array type containing Num_Tasks of Filler tasks; 
    type Task_List is array(Natural range 0..Num_tasks - 1) of Filler; 

    -- Create an instance of the task array. The tasks start as soon 
    -- as this array is created 
    List  : Task_List; 

begin -- begin the execution of the main task 
    -- Send ID values to each instance of the Filler task in the array 
    -- List. 
    for I in Task_List'Range loop 
     List(I).Set_Low(I); 
    end loop; 

    loop -- waits for all the tasks to terminate 
     if List(0)'Terminated and then 
     List(1)'Terminated and then 
     List(2)'Terminated and then 
     List(3)'Terminated and then 
     List(4)'Terminated and then 
     List(5)'Terminated and then 
     List(6)'Terminated and then 
     List(7)'Terminated then 
     exit; -- exit this loop 
     end if; 
    end loop; 

    Put_Line("Elapsed time " & Duration'Image(Clock - Start_Time) & " seconds"); 
end Array_Fill; 
관련 문제