EETOP 创芯网论坛 (原名:电子顶级开发网)

标题: sv里的fork_join线程问题 [打印本页]

作者: 打回原形    时间: 2016-4-4 11:53
标题: sv里的fork_join线程问题
代码里已经把program声明为qutomatic了,表明for循环里的变量i是automatic,并不是只分配一块共享内存放置i啊
[attach]650534[/attach]
运行结果为:
[attach]650535[/attach]
我觉得应该有16个内存区域放置i的中间值,应该从port0到port15才对啊.请大神解释下,谢谢
作者: 打回原形    时间: 2016-4-4 11:56
( , 下载次数: 73 ) ( , 下载次数: 83 ) 回复 1# 打回原形
图片上传失败了,这是图片
作者: 打回原形    时间: 2016-4-4 12:52
回复 2# 打回原形

我把 i 声明为静态的,结果居然和动态 i 运行的一样,怎么回事啊 ( , 下载次数: 71 )
作者: hover99    时间: 2016-4-5 10:37
for (int ii = 0; ii < 16; ii+=)
    fork
        begin
            automatic int jj;
            jj = ii;
            send(jj);
        end
    join_none
end
作者: 打回原形    时间: 2016-4-5 14:17
回复 4# hover99

我知道声明一个中间自动变量可以解决,但是automatic的program里面的变量默认是automatic,那么for循环里的 i 也是automatic, 按道理没必要中间再复制一份吧。一般加中间自动变量用于解决static的program,还望大神解释下我截的两张图中同样在automatic的program
中,automatic的 i 和 static的 i 为啥得到相同的结果,两者的变量内存分配是怎么回事,谢谢
作者: AnswerLJ    时间: 2016-4-5 15:53


   

        

                
  1. program automatic test ;
  2.     int i; // not within a procedural block - static
  3.     task t ( int a ); // arguments and variables in t are automatic
  4.         ... // unless explicitly declared static
  5.     endtask
  6. endprogram
            

   

    复制代码
IEEE 1800-2012有解释
作者: hover99    时间: 2016-4-5 17:04
回复 5# 打回原形
不好意思,说错了。应该这样改:task automatic send(int j);
fork
  begin
     $display();
     #1;
   end
join_none
endtask


initial begin
    for (int ii = 0; ii < 16; ii ++) begin
       send(ii);
    end
end
仿真器遇到fork join_none语句,会直接跳到join_none之后继续执行直到遇到阻塞语句。在你的例子里,仿真器会先执行16次for循环,然后才会执行16个fork,所以在fork里面看到的ii会是16.
作者: 打回原形    时间: 2016-4-5 19:33
回复 7# hover99

谢谢啊,我懂了




欢迎光临 EETOP 创芯网论坛 (原名:电子顶级开发网) (https://bbs.eetop.cn/) Powered by Discuz! X3.5