# VecLockWriteSet
Lock or unlock a vector for exclusive read/write access 
## Synopsis
```
#include "petscvec.h"   
PetscErrorCode VecLockWriteSet(Vec x, PetscBool flg)
```
Logically Collective


## Input Parameters

- ***x   -*** the vector
- ***flg -*** PETSC_TRUE to lock the vector for exclusive read/write access; PETSC_FALSE to unlock it.





## Notes
The function is useful in split-phase computations, which usually have a begin phase and an end phase.
One can call `VecLockWriteSet`(x,`PETSC_TRUE`) in the begin phase to lock a vector for exclusive
access, and call `VecLockWriteSet`(x,`PETSC_FALSE`) in the end phase to unlock the vector from exclusive
access. In this way, one is ensured no other operations can access the vector in between. The code may like

```none
       VecGetArray(x,&xdata); // begin phase
       VecLockWriteSet(v,PETSC_TRUE);

       Other operations, which can not access x anymore (they can access xdata, of course)

       VecRestoreArray(x,&vdata); // end phase
       VecLockWriteSet(v,PETSC_FALSE);
```


The call can not be nested on the same vector, in other words, one can not call `VecLockWriteSet`(x,`PETSC_TRUE`)
again before calling `VecLockWriteSet`(v,`PETSC_FALSE`).


## See Also
 [](chapter_vectors), `Vec`, `VecRestoreArray()`, `VecGetArrayRead()`, `VecLockReadPush()`, `VecLockReadPop()`, `VecLockGet()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/interface/rvector.c.html#VecLockWriteSet">src/vec/vec/interface/rvector.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/vec/vec/interface/rvector.c)


[Index of all Vec routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
