Note that there are some explanatory texts on larger screens.

plurals
  1. POSharing and locking a fixed number resources of between multiple threads
    primarykey
    data
    text
    <p>I have a fixed number <code>n</code> of identical resources that need to be shared between <code>n</code> or more threads. Whenever a thread needs to use a resource, it can take any available one, for which it runs an indetermininate amount of time (i.e. usage times are not uniform) and then release it.</p> <p>What is a good Java data structure to manage this scenario? I can only think of one way to do it, which is by using a <code>LinkedBlockingQueue</code> and the <code>take</code> and <code>put</code> operations as locking and releasing a resource, respectively. I'd just like a suggestion from the concurrency experts:</p> <p>For those who are curious: The resources that need to be shared are identical copies of a <a href="https://stackoverflow.com/q/14553996/586086">non-reentrant FORTRAN library</a> for computing multivariate normal CDFs and moments. Spectacular numerical library, but written in an age where thread-safe code wasn't something to be worried about. In this case we make <code>n</code> copies of the library, where <code>n = Runtime.getRuntime().availableProcessors()</code> .</p> <p><strong>EDIT</strong>: I don't want to create the overhead of threads to execute this library. It is already being called from multiple threads; the calling threads should just be able to lock a resource and get on with it.</p> <p><strong>UPDATE</strong>: See <a href="https://stackoverflow.com/a/19039878/586086">https://stackoverflow.com/a/19039878/586086</a> for the motivation and the implementation.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload