Skip to content

A subsystem for multi-process shared memory in MATLAB.

License

Notifications You must be signed in to change notification settings

gharveymn/matshare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

matshare

matshare is a subsystem for MATLAB R2008b to R2017b which provides functions for creating and operating on shared memory. It has mechanisms for automatic garbage collection, thread-safe memory creation, and in-place overwriting.

Availability

MATLAB R2008b to R2017b on Windows and Linux. This is not available for R2018a+ yet because of changes made the MEX API. This is also not available for MacOS partially because of problems with locking files but mainly because I don't own a Mac.

Usage

First pick up the latest release. You may need to compile matshare if you are running Linux, in which case just navigate to source and run INSTALL.m.

Simple Example

Process 1
>> matshare.share(rand(3));
Process 2
>> fetched = matshare.fetch
fetched = 
  matshare object storing 3x3 double:
    data: [3×3 double]
>> fetched.data
ans =
         0.814723686393179         0.913375856139019         0.278498218867048
         0.905791937075619          0.63235924622541         0.546881519204984
         0.126986816293506        0.0975404049994095         0.957506835434298    

Named Variables and Overwriting

Process 1
>> shared = matshare.share('-n', 'myvarname', 1);
>> shared.data
ans =
     1
Process 2
>> f = matshare.fetch('myvarname')
f = 
  matshare object storing 1x1 double:
    data: 1
>> f.data(1) = 2;    
Process 1
>> shared.data
ans =
     2

Variable Operations

Process 1
>> shared = matshare.share(1);
>> shared.data
ans =
     1
Process 2
>> f = matshare.fetch
f = 
  matshare object storing 1x1 double:
    data: 1
>> f.add(2);    
Process 1
>> shared.data
ans =
     3

This, and all the other operations can be made synchronous through mutexes or lockfree intrinsics.

For more details, you can navigate through the documentation with help matshare or help matshare.[command], replacing [command] with any one of the matshare commands.

Future Development

This project is pretty much complete save for the inevitable bugs. However these may be implemented at some point in the future:

  • Variable identifiers (being able to select shared variables by name)
  • Atomic variable operations (increments, decrements, swaps, etc.)
  • Variable overwriting by index
  • Thread locks on a sub-global level
  • Rewrite in C++ for R2018a+
  • User defined locks/waits
  • Direct usage of matshare objects without the 'data' property

If you wish to contribute or have any suggestions feel free to contact me.

License

This project is licensed under the MIT license.

About

A subsystem for multi-process shared memory in MATLAB.

Resources

License

Stars

Watchers

Forks

Packages

No packages published