MultiProcessor Execution

Demo: 3-Core helloworld Using Threads

The following demo outputs "Hello, World!" individually, from the main core, sub-Core 1, and sub-Core 2.

$CAFE_ROOT/system/src/demo/os/basic_mp/helloworld_3cores.c

Demo: Allocate Memory from Per-Core Threads

The following demo shows how to allocate the default heap memory from multiple cores. The default heap is created thread-safe.

$CAFE_ROOT/system/src/demo/os/basic_mp/alloc_from_3cores.c

Demo: Create Per-Core Heaps Using 3 Threads to Access the Separate Heaps

The following demo shows how to create a heap for each core and allocate memory independently.

$CAFE_ROOT/system/src/demo/os/basic_mp/alloc_percore_heap.c

By limiting the access of any given heap to only one thread at one time, the need for exclusive control is eliminated. This allows users to access the heap quickly.

Proper Separation and Synchronization of Global Data

Demo: Use Spinlocks with Threads Across Multiple Cores

In the following demo, data is inserted into the linked list using three threads, and then the three threads sort the data simultaneously. To prevent multiple threads from accessing the linked list at the same time and possibly destroying it, the linked list is protected by the use of spinlock.

$CAFE_ROOT/system/src/demo/os/basic_mp/spinlock_across_cores.c

Demo: Use Mutex with Threads Across Multiple Cores

In the following demo, six threads increment values in the buffer 10 times each. There are two buffers, one of which is protected by Mutex and the other of which is not. Thread synchronization for the protected buffer means accurate computation results.

$CAFE_ROOT/system/src/demo/os/basic_mp/mutex_across_cores.c

Demo: Use Semaphores with Threads Across Multiple Cores

In the following demo, six threads share two resources. Using semaphores, the number of resources to be used at the same time is limited to two.

$CAFE_ROOT/system/src/demo/os/basic_mp/semaphore_across_cores.c

Demo: "Hot Locks"

The following demo uses three threads to compute the sum of numerical values in the data array. Because this sum is recorded into the global variable protected by spinlock, multiple threads fight over the spinlock. This type of spinlock, called a hot lock, contributes to performance deterioration.

$CAFE_ROOT/system/src/demo/os/basic_mp/hot_lock.c

Demo: Strategy to Help Avoid "Hot Locks"

The following demo uses three threads to compute the sum of numerical values in the data array. Each thread records the sum into the local variable for that thread. When computation on each thread finishes, the demo gets a spinlock only once, and combines the sum of each thread into the sum of the total.

$CAFE_ROOT/system/src/demo/os/basic_mp/avoid_hot_lock.c

By using local variables for each thread, the number of incidents requiring the spinlock may be reduced, which helps resolve the hot lock issue.

Demo: Strategy to Avoid Help "Hot Locks" Using the OSAtomic API

The following demo uses three threads to compute the sum of numerical values in the data array. Each thread records the sum in the global variable by using the OSAtomic API. The OSAtomic functions change variables atomically, so it is not necessary to protect variables with a spinlock. If the critical section has only one variable, the processing speed can improve by using the OSAtomic API.

$CAFE_ROOT/system/src/demo/os/basic_mp/avoid_hot_lock_using_OSAtomicAPI.c

Demo: Use Conditional Variables with Threads Across All Cores

One Producer places 18 items into the buffer for six consumers. The maximum number of items that can be stored in the buffer is four.

$CAFE_ROOT/system/src/demo/os/basic_mp/condition_variable_across_cores.c

Demo: Use Message Queues with Threads Across Multiple Cores

In the following demo, six clients obtain three IDs, each from one ID-generating server. The clients and server use the message queue to exchange.

$CAFE_ROOT/system/src/demo/os/basic_mp/message_queue_across_cores.c

Demo: Use OSEvents with Threads Across Multiple Cores

In the following demo, six clients obtain three IDs each from one ID-generating server, and uses events as notification of the sending and receiving requests.

$CAFE_ROOT/system/src/demo/os/basic_mp/event_across_cores.c

Revision History

2013-05-08 Automated cleanup pass.
2013-03-20 Converted to HTML.


CONFIDENTIAL