1

I have several processes (on the same computer) which together need to sequentially access the elements of an array in shared memory. To do this I want to store the current index into the array as an int in shared memory, and for each of the processes to be able to get the current value of the index and increment it by a fixed value in one single atomic operation. How can I do this in Java?

Note: I only want this atomic operation coded in Java. The rest of the code happens to be in MATLAB.

4

2 回答 2

1

您可以使用文件系统:Getting exclusive system-wide lock in Java

或者,如果您可以改用 C,那么您可以在共享内存中创建一个 POSIX 互斥锁:Linux Shared Memory Synchronization

于 2014-01-20T23:22:01.473 回答
0

知道你想要做什么是有必要的。但是,只是尝试一下-您可能需要某种内存数据库。

甲骨文把我带到了这里:http: //java.dzone.com/articles/using-shared-memory-java,但也有类似 h2 的东西(http://www.h2database.com/html/main.html),我以前用过,效果很好。

让我们知道您要完成的工作,我们可能会提供更多帮助。

于 2013-10-24T23:23:18.397 回答