函数fork(&)的bash变量范围问题

时间:2016-08-13 06:15:30

标签: bash variables scope fork

我想同时运行函数 public void updateAdapter (Boolean isFavoriteActive ){ ChannelsQueryRealm = realm.where(Channels.class) .equalTo("isFavourite", true) .findAll(); // here i fetched the data that i want to put in my recyclerView channelsIDArray.clear(); channelIsFavoriteArray.clear(); for (Channels channels : ChannelsQueryRealm) { channelsIDArray.add(channels.getObjectId()); channelIsFavoriteArray.add(channels.getIsFavourite()); } // here i added new updated data in my array's new Runnable() { public void run() { channelsAdapter.notifyDataSetChanged(); // and here i'm trying to reflect the change but its not working fine because the updated change is not reflecting correctly on desired row } }; } f1,然后只有在完成后才执行操作。
似乎如果函数在脚本中是后向的,脚本看不到f2值更改,直到循环不会终止并且不执行最后一行。

  1. 应如何实施?
  2. 编辑 - 需要其他功能
    2.有没有办法可以读取/写入脚本中的主流程变量(不使用文件)?

    感谢您的阅读。

    f1/f2done

1 个答案:

答案 0 :(得分:5)

f1f2将是独立的进程,因此具有与主进程分开的地址空间。因此你的循环将是无限的。

您需要改为使用wait

变化

until [[ "$f1done" == "true" && "$f2done" == "true" ]]; do
    echo "$f1done $f2done...";
     sleep 3;
done

wait;
wait;
相关问题