File Locking/sharing, cross platform

267 views
Skip to first unread message

you...@z505.com

unread,
Feb 10, 2016, 8:52:47 PM2/10/16
to golang-nuts
When I was searching for how to lock a file in GoLang it appears there are OS specific ways of doing it such as calling OS specific file locking mechanisms. Is there a better way that is not operating system specific? i.e. libraries that lock files cross platform without resorting to lower level operating system API calls?

Any plans to do this, or has someone already written something on Github that wraps the lower level locking calls into a library?

Otherwise I'm going to have to use lockfile on unix and windows api calls on MS Windows?

Example of what I mean by file locking:  10 different people access the same file simutaneously. This is bad. So you lock the file and each person gets their turn. Since there is no cross platform file locking (AFAIK) this means using a database instead, is tempting, since the database does the work for you - however I would like to write to files and avoid database for a simple program.

Tamás Gulácsi

unread,
Feb 11, 2016, 12:34:18 AM2/11/16
to golang-nuts
You can try go4.org/lock or github.com/tgulacsi/lock

Or if you control all the accessing programs, binding on a fixed port also works as an ipc mutex.

Reply all
Reply to author
Forward
0 new messages