I am trying to figure out what locks do. There are lots of example of how to get and set them, and an api to do the same.
The documentation says they are used to share memory or resources between cores/tasks.
What what do they actually do?
How do they actually work?
What exactly do locks do and how do they work?
-
- XCore Addict
- Posts: 204
- Joined: Sun Jun 01, 2014 10:25 pm
-
- XCore Expert
- Posts: 754
- Joined: Thu Dec 10, 2009 6:56 pm
The are thread synchronisation mechanisms just like semaphores and the like.
Once a lock is acquired it cannot be acquired by another thread until the lock is released (if properly programmed).
In shared memory configurations one could use them to ensure that only one thread will make changes to the shared memory at a time (mutual exclusion).
XMOS advocates to use channels for synchronisation, so you don't see the locks very often used, but it's there.
Once a lock is acquired it cannot be acquired by another thread until the lock is released (if properly programmed).
In shared memory configurations one could use them to ensure that only one thread will make changes to the shared memory at a time (mutual exclusion).
XMOS advocates to use channels for synchronisation, so you don't see the locks very often used, but it's there.
-
- Active Member
- Posts: 38
- Joined: Fri Oct 28, 2011 10:53 pm
Is there a non-dogmatic reason why use of locks isn't encouraged? The XMOS implementation of locks is absolutely beautiful.
In answer to the original question: locks don't exactly *do* anything, but the idea is that all users of a shared data structure agree that they'll touch it only while holding a particular lock.
In answer to the original question: locks don't exactly *do* anything, but the idea is that all users of a shared data structure agree that they'll touch it only while holding a particular lock.
-
- XCore Addict
- Posts: 204
- Joined: Sun Jun 01, 2014 10:25 pm
Could someone post a short programming example of how they work?
-
- XCore Expert
- Posts: 754
- Joined: Thu Dec 10, 2009 6:56 pm
Did you take a look at https://github.com/xmos/lib_locks
-
- XCore Addict
- Posts: 204
- Joined: Sun Jun 01, 2014 10:25 pm
Thanks, that helps.