Пример #1
0
 void abc()
 {
     for ( int i = 0; i < 3; i++ )
     {
         cout << "Time  Spawn Start Stop " << endl;
         cout << "----- ----- ----- ----" << endl;
         int              ii = 2;
         int              spawn_i;
         int              spawn_n = 8;
         sc_spawn_options options;
         sc_join          join;
         options.set_sensitivity(&m_clk.pos());
         for ( spawn_i = 0; spawn_i < spawn_n; spawn_i++ )
         {
             int process_i = spawn_i + i * spawn_n;
             cout << sc_time_stamp() << " " << process_i << endl;
             join.add_process(sc_spawn(
                                  sc_bind(&TB::process, this, sc_ref(process_i)),
                                  sc_gen_unique_name("pipe"), &options ) );
             sc_core::wait(ii);
         }
         cout << sc_time_stamp() << " waiting for termination of "
              << join.process_count() << " processes" << endl;
         join.wait();
         cout << sc_time_stamp() << " back from termination wait " << endl;
     }
 }
Пример #2
0
    void main()
    {
        int r;
        sc_event e1, e2, e3, e4;

        cout << endl;

        e1.notify(100, SC_NS);

        // Spawn several threads that co-operatively execute in round robin order

        SC_FORK
        sc_spawn(&r,
                 sc_bind(&top::round_robin, this, "1", sc_ref(e1), sc_ref(e2), 3), "1") ,
        sc_spawn(&r,
                 sc_bind(&top::round_robin, this, "2", sc_ref(e2), sc_ref(e3), 3), "2") ,
        sc_spawn(&r,
                 sc_bind(&top::round_robin, this, "3", sc_ref(e3), sc_ref(e4), 3), "3") ,
        sc_spawn(&r,
                 sc_bind(&top::round_robin, this, "4", sc_ref(e4), sc_ref(e1), 3), "4") ,
        SC_JOIN

        cout << "Returned int is " << r << endl;
        cout << endl << endl;

        // Test that threads in thread pool are successfully reused ...

        for (int i = 0 ; i < 10; i++)
            sc_spawn(&r, sc_bind(&top::wait_and_end, this, i));

        wait(20, SC_NS);

        // Show how to use sc_spawn_options

        sc_spawn_options o;
        o.set_stack_size(0);


        // Demo of a function rather than method call, & use return value ...

        wait( sc_spawn(&r, sc_bind(&test_function, 3.14159)).terminated_event());

        cout << "Returned int is " << r << endl;

        sc_process_handle handle1 = sc_spawn(sc_bind(&void_function, 1.2345));
        wait(handle1.terminated_event());

        double d = 9.8765;
        wait( sc_spawn(&r, sc_bind(&ref_function, sc_cref(d))).terminated_event() );

        cout << "Returned int is " << r << endl;

        cout << endl << "Done." << endl;
    }
Пример #3
0
void FrSimIfaceSysc::wait(FrSimCond c) {
  // Need to spawn an sysc dynamic thread
  // Sysc Thread does:
  //   1) wait for value_change_event of signal in c
  //   2) test condition, if not met return to 1)
  //   3) trigger FrSim thread passed in
  // do a wait on the FrSim thread

  FrSimThread *thr = FrSimThread::getSelf();
  sc_spawn(sc_bind(&FrSimIfaceSysc::syscSignalEvent, sc_reg(&c), sc_ref(thr)));
  thr->wait();
}