相关疑难解决方法(0)

在多个chrome.storage API调用中防止竞争条件的最佳方法是什么?

  1. 某事要求任务
  2. 其他东西将任务列表从存储中拉出来,并检查那里是否有任务.
  3. 如果有任务则删除一个,较小的"任务列表"将被放回存储中.

在步骤2和3之间,如果发生多个请求,则可能发生竞争条件,并且相同的任务将被提供两次.

在单个任务被"签出"时,是否"锁定""任务表"是正确的解决方案,以防止任何其他请求?

什么是性能影响最小的解决方案,例如延迟执行,以及如何使用chrome.storage API在javascript中实现?

一些代码例如:

function decide_response ( ) {
    if(script.replay_type == "reissue") {
            function next_task( tasks ) {
                var no_tasks = (tasks.length == 0);
                if( no_tasks ) {
                    target_complete_responses.close_requester();
                }
                else {
                    var next_task = tasks.pop();
                    function notify_execute () {
                        target_complete_responses.notify_requester_execute( next_task );
                    }
                    setTable("tasks", tasks, notify_execute);
                }
            }
            getTable( "tasks", next_tasks );
    ...
    }
...
}
Run Code Online (Sandbox Code Playgroud)

javascript locking race-condition google-chrome-extension

10
推荐指数
1
解决办法
2005
查看次数