# Just want to make sure I'm using InterProcessLock Correctly

**URL:** <https://forum.juce.com/t/just-want-to-make-sure-im-using-interprocesslock-correctly/50376>\
**Category:** General JUCE discussion\
**Created:** [February 26, 2022, 10:06pm UTC](https://forum.juce.com/t/just-want-to-make-sure-im-using-interprocesslock-correctly/50376 "2022-02-26T22:06:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wiznat](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/wiznat/32/11103_2.png) [@Wiznat](https://forum.juce.com/u/Wiznat)\
**Post date:** [February 26, 2022, 10:06pm UTC](https://forum.juce.com/t/just-want-to-make-sure-im-using-interprocesslock-correctly/50376/1 "2022-02-26T22:06:29Z")

</div>

Hey, just looking for someone to let me know if I’m using InterProcessLock Correctly.

Basically, I have a ValueTree that needs to get saved to disk periodically.

Right now my save() function looks something like this

```auto
void Profile::save()
{
    //SaveLock is declared in the memeber variables as a InterProcessLock
    const InterProcessLock::ScopedLockType sl (saveLock);
    
    saveFile.deleteFile();
    FileOutputStream os(saveFile);
    playerTree.writeToStream(os);
    lastModTime = saveFile.getLastModificationTime();
    needsToSave = false;
    autoSaveCounter = 0;
}

```

Everything works fine, I’m just not too familiar with multithreading and locks so just want to double check this is correct. Sorry if this posts seems dumb lol

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [February 27, 2022, 4:14pm UTC](https://forum.juce.com/t/just-want-to-make-sure-im-using-interprocesslock-correctly/50376/2 "2022-02-27T16:14:10Z")

</div>

This lock is designed to work between different processes, not between threads. You want to use a CriticalSection for threads. Also, what is the data you want to protect from multithread access? Unless you are protecting file access, I would NOT lock for the file operation. Ideally you could lock, copy the data, unlock and do file operations with copy.
