1如何通过接口呼叫传递指针
接口函数可以接受指针参数:
- interface my_interface {
- void msg(int *p);
- };
复制代码
然后,客户端可以将指针传递到该功能中:
- void task1(client interface my_interface c)
- {
- int a[5] = {0,1,2,3,4};
- int *p = &a[0];
- c.msg(p);
- }
复制代码
在服务器结束时,选择情况可以通过指针访问内存。
- void task2(server interface my_interface c)
- {
- select {
- case c.msg(int *p):
- printintln(*p);
- printintln(*(p+2));
- break;
- }
- }
复制代码
由于传递指针意味着两个任务都需要访问相同的内存空间,因此,如果接口包含传递指针的函数,则不能在不同图块上的任务之间使用它。