Android game help

I need help with three threads in Android

One thread is the main thread, the other is GLThread, and the other is WorkerThread, which I created to update the state of the game.

The problem I have is all that is needed to access the same LinkedList of game objects. Both GLThread and my WorkerThread are read only from LinkedList, so there is no problem, but sometimes I have a main thread adding a list to another game object.

How can i do this? I tried using synchronization before functions, but it really slows down the application.

For some reason, just catching errors, rather than rendering or updating the state of the game, that frame, makes it constantly linger.

Anyone have any great ideas?

+3
source share
2 answers

I would suggest an instance of CopyOnWriteArrayList. This copies the support list when it mutates, but allows an unsynchronized read with the trade-off that you have been reading the list from the point in time regarding the entries.

+1
source

: , CAS ( ) , . , , , CAS . , . CAS - AtomicReference Java ... Software Monkey , CopyOnWriteArrayList.

Java concurrency library, - , ConcurrentHashMap.

0

Source: https://habr.com/ru/post/1736827/


All Articles