Multicore and...
QNX SDP8.0Programmer's GuideDeveloper
- Synchronization primitives
- Standard synchronization primitives (barriers, mutexes, condvars, semaphores, and all of their derivatives) are safe to use on a multicore box. You don't have to do anything special here.
- FIFO scheduling
- A common single-processor
trick
for coordinated access to a shared memory region is to use FIFO scheduling between two threads running at the same priority. The idea is that one thread will access the region and then call SchedYield() to give up its use of the processor. Then, the second thread runs and accesses the region. When it's done, the second thread too calls SchedYield(), and the first thread runs again. Since there's only one processor, both threads would cooperatively share that processor.This FIFO trick won't work on an SMP system, because both threads may run simultaneously on different processors. You'll have to use the more
proper
thread synchronization primitives (e.g., a mutex), or use BMP to tie the threads to specific CPUs. - Atomic operations
- Note that if you wish to perform simple atomic operations,
such as adding a value to a memory location, it isn't necessary
to turn off interrupts to ensure that the operation won't be preempted.
Instead, use the functions provided in the C include file
<atomic.h>, which let you perform
the following operations with memory locations in an atomic manner:
Function Operation atomic_add() Add a number atomic_add_value() Add a number and return the original value of *loc atomic_clr() Clear bits atomic_clr_value() Clear bits and return the original value of *loc atomic_set() Set bits atomic_set_value() Set bits and return the original value of *loc atomic_sub() Subtract a number atomic_sub_value() Subtract a number and return the original value of *loc atomic_toggle() Toggle (complement) bits atomic_toggle_value() Toggle (complement) bits and return the original value of *loc Note:The *_value() functions may be slower on some systems, so don't use them unless you really want the return value.
Page updated: