PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
propsideworkspace
Learn
Examples
C Intro
Functions
Multicore Example.c
1
/*
2
Multicore Example.c
3
4
Launch a function into another cog (processor) and display what it does
5
to the global n variable over time.
6
7
http://learn.parallax.com/propeller-c-functions/multicore-example
8
*/
9
10
#include "simpletools.h"
// Include simpletools
11
12
void
adder(
void
*par);
// Forward declaration
13
14
static
volatile
int
t, n;
// Global vars for cogs to share
15
unsigned
int
stack[44 + 128];
// Stack vars for other cog
16
17
int
main
()
// main function
18
{
19
t = 50;
// Set values of t & n
20
n = 5000;
21
22
// Launch adder function into another cog (processor).
23
cogstart(adder, NULL, stack,
sizeof
(stack));
24
25
// Watch what the other cog is doing to the value of n.
26
while
(1)
27
{
28
print(
"n = %d\n"
, n);
// Display result
29
pause(100);
// Wait 1/10 of a second
30
}
31
}
32
33
// Function that can continue on its
34
// own if launched into another cog.
35
void
adder(
void
*par)
// Adder keeps going on its own
36
{
37
while
(1)
// Endless loop
38
{
39
n = n + 1;
// n + 1 each time loop repeats
40
pause(t);
// Wait for t ms between updates
41
}
42
}
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Sat Aug 27 2016 00:58:03 for PropWare by
1.8.12