Skip to content

Multithreading use tilecache #141

Answered by ppiastucki
shadowerzc asked this question in Q&A
Discussion options

You must be logged in to vote

The library is not designed to handle navmesh updates and pathfinding concurrently. The place you mentioned could be made thread-safe but there might be other places to change too. Using CopyOnWriteArrayList will not work as it would also require replacing the reference to the list.
The proper approach would be to use a Lock or a Semaphore to make sure navmesh updates do no overlap with ongoing path searches.
E.g.

    ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(true);

    void updateNavmesh() {
        rwLock.writeLock().lock();
        try {
            // run navmesh update here
        } finally {
            rwLock.writeLock().unlock();
        }
    }
	
    void findP…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ppiastucki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #140 on November 01, 2022 07:25.