P
Philipp
Hello
I want to make an existing library thread-safe as it is now accessed
through several threads.
The work in the library is done by a single internal thread. External
events to be processed are posted to a blocking priority queue and
then taken up by that internal thread in the lib. This part is thread
safe.
I also have getters to read the present state of the lib and setters
to set parameters which define how the events are treated. Both of
these are accessed by several threads and not yet thread safe.
In order to make these safe, I see two possibilities (please comment
if others exist).
1. Protect the accessed fields with synchronisation.
2. Make all requests into Futures which are posted to the queue and
are processed by the internal thread.
What are the pro's and con's of the two approaches?
In particular regarding:
- throuput
- ease of developing non-deadlocking code
- possibility to increase the number of "worker" threads later on
Thanks for your input
Philipp
I want to make an existing library thread-safe as it is now accessed
through several threads.
The work in the library is done by a single internal thread. External
events to be processed are posted to a blocking priority queue and
then taken up by that internal thread in the lib. This part is thread
safe.
I also have getters to read the present state of the lib and setters
to set parameters which define how the events are treated. Both of
these are accessed by several threads and not yet thread safe.
In order to make these safe, I see two possibilities (please comment
if others exist).
1. Protect the accessed fields with synchronisation.
2. Make all requests into Futures which are posted to the queue and
are processed by the internal thread.
What are the pro's and con's of the two approaches?
In particular regarding:
- throuput
- ease of developing non-deadlocking code
- possibility to increase the number of "worker" threads later on
Thanks for your input
Philipp