Skip to content

Instantly share code, notes, and snippets.

@AdityaDeshmane
Last active January 14, 2025 13:11
Show Gist options
  • Save AdityaDeshmane/0d3a92c0454a915abda7 to your computer and use it in GitHub Desktop.
Save AdityaDeshmane/0d3a92c0454a915abda7 to your computer and use it in GitHub Desktop.
iOS : NSCondition Lock Example
-(sqlite3 *) getConnection
{
@try
{
[connMutex lock];
while (bInUse == YES)
{
[connMutex wait];
}
bInUse = YES;
return _database;
}
@catch(NSException *e)
{
return NULL;
}
@finally
{
[connMutex unlock];
}
return NULL;
}
-(void) releaseConnection
{
@try
{
[connMutex lock];
if(bInUse == YES)
{
bInUse = NO;
[connMutex signal];
}
}
@catch(NSException *e)
{
return;
}
@finally
{
[connMutex unlock];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment