1

I can't seem to find any read-write locks for Objective C. This is for iphone dev. Any ideas? The appendix in this paper has some code, but it is incomplete.

mipadi
  • 398,885
  • 90
  • 523
  • 479
Jacko
  • 12,665
  • 18
  • 75
  • 126

2 Answers2

0

Foundation provides NSLock to help you lock and unlock threads but I think it could help you.

albianto
  • 4,092
  • 2
  • 36
  • 54
0

You can use dispatch_barrier_async function and a concurrent queue to implement a read-write lock.

    dispatch_queue_t queue = dispatch_queue_create("your queue name", DISPATCH_QUEUE_CONCURRENT);
    dispatch_async(queue, ^{
        // execute read task 1
    });
    dispatch_async(queue, ^{
        // execute read task 2
    });
    dispatch_barrier_async(queue, ^{
        // execute write task 1
    });
Michael
  • 415
  • 6
  • 16