1 #include <cyg/kernel/kapi.h>
7 /* now declare (and allocate space for) some kernel objects,
8 like the two threads we will use */
9 cyg_thread thread_s[2]; /* space for two thread objects */
11 char stack[2][4096]; /* space for two 4K stacks */
13 /* now the handles for the threads */
14 cyg_handle_t simple_threadA, simple_threadB;
16 /* and now variables for the procedure which is the thread */
17 cyg_thread_entry_t simple_program;
19 /* and now a mutex to protect calls to the C library */
22 /* we install our own startup routine which sets up threads */
23 void cyg_user_start(void)
25 printf("Entering twothreads' cyg_user_start() function\n");
27 cyg_mutex_init(&cliblock);
29 cyg_thread_create(4, simple_program, (cyg_addrword_t) 0,
30 "Thread A", (void *) stack[0], 4096,
31 &simple_threadA, &thread_s[0]);
32 cyg_thread_create(4, simple_program, (cyg_addrword_t) 1,
33 "Thread B", (void *) stack[1], 4096,
34 &simple_threadB, &thread_s[1]);
36 cyg_thread_resume(simple_threadA);
37 cyg_thread_resume(simple_threadB);
40 /* this is a simple program which runs in a thread */
41 void simple_program(cyg_addrword_t data)
43 int message = (int) data;
46 printf("Beginning execution; thread data is %d\n", message);
48 cyg_thread_delay(200);
51 delay = 200 + (rand() % 50);
53 /* note: printf() must be protected by a
54 call to cyg_mutex_lock() */
55 cyg_mutex_lock(&cliblock); {
56 printf("Thread %d: and now a delay of %d clock ticks\n",
59 cyg_mutex_unlock(&cliblock);
60 cyg_thread_delay(delay);