I need a C equivalent of the following Java class. It is a queue lock known as an Anderson Lock used in thread synchronization. I am not comfortable using C, and there are some thread classes which I don't really know how to use. thanks.
I am using OpenSolaris.
public class ALock implements Lock { ThreadLocal mySlotIndex = new ThreadLocal (){ protected Integer initialValue() { return 0; } }; AtomicInteger tail; boolean[] flag; int size; public ALock(int capacity) { size = capacity; tail = new AtomicInteger(0); flag = new boolean[capacity]; flag[0] = true; } public void lock() { int slot = tail.getAndIncrement() % size; mySlotIndex.set(slot); while (! flag[slot]) {}; } public void unlock() { int slot = mySlotIndex.get(); flag[slot] = false; flag[(slot + 1) % size] = true; } }