forked from luxkun/ReGoap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use concurrent queue and dictionary to avoid race conditions.
With Unity2019.1.0a13 the example scene had failures with WorksQueue.Dequeue() initially. Presumably this is because the WorksQueue.Count test and Dequeue() happen at different times. To fix this, I switched WorksQueue to a ConcurrentQueue and use TryDequeue() which dequeues atomically if there is an item available and returns true; otherwise, it returns false. After that was fixed, a new error popped up when the trees ran out. This appeared to be caused by a race condition between the test for HasKey and Get. To fix this, I switched the dictionaries in ReGoapState to ConcurrentDictionary classes. And I removed Get() in favor of TryGetValue() which avoids that race condition. The example scene works. All unit tests pass. I hope these bugs mean that Unity is using more threads than it was before.
- Loading branch information
1 parent
506600c
commit c21d7c2
Showing
5 changed files
with
45 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters