Channel Synchronization in VHDL

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity ChannelSynchronization is
end ChannelSynchronization;

architecture Behavioral of ChannelSynchronization is
    signal done : std_logic := '0';
begin
    -- This is the process we'll run as a separate thread. The
    -- 'done' signal will be used to notify the main process
    -- that this process's work is done.
    worker_process: process
    begin
        report "working...";
        wait for 1 sec;
        report "done";
        
        -- Set the signal to notify that we're done.
        done <= '1';
        wait;
    end process;

    -- Main process
    main_process: process
    begin
        -- Start the worker process
        
        -- Wait until we receive a notification from the
        -- worker on the 'done' signal.
        wait until done = '1';
        
        -- End simulation
        wait;
    end process;
end Behavioral;

This VHDL code demonstrates a simple synchronization mechanism between two processes, which is analogous to the channel synchronization in the original example.

In VHDL, we use processes to represent concurrent execution, similar to goroutines. The worker_process simulates work by waiting for 1 second and then setting a done signal. The main_process waits for this signal before completing.

To simulate this design:

$ ghdl -a channel_synchronization.vhd
$ ghdl -e channel_synchronization
$ ghdl -r channel_synchronization --stop-time=2sec
working...
done

The simulation will output “working…” immediately, then “done” after 1 second, and then stop after 2 seconds total.

If you removed the wait until done = '1'; line from the main process, the simulation would end immediately without waiting for the worker process to complete.

Note that VHDL is typically used for hardware description and simulation, so the concept of “running” the program is different from software languages. Instead, we simulate the design for a specified time period.