Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using IThread

Base version: Brew MP 1.0
Tested version: Brew MP 1.0
Phone tested: Yes

You can use the Brew® Mobile Platform (Brew MP) IThread interface to write applications that use cooperative multithreading. Cooperative multithreading requires that threads give up control so that other threads can execute.

IThread exports functions to start, stop, and suspend threads, as well as functions to set up a callback to be invoked when a thread is resumed, and to set up a callback to be invoked when a thread terminates.

Objective

This document describes how to do the following:

  • Create threads
  • Set up a callback to be invoked when a thread terminates
  • Yield so that other threads can execute

Examples of the above are shown in the sections that follow.

For more information on IThread, see the C/C++API Reference.

Requirements

The application needs to include AEEThread.h.

Sample code location

The c_samplethread sample code shown in this document creates three threads:

  • Thread 1 displays a timer
  • Thread 2 displays an arc that moves around a circle
  • Thread 3 displays the degree used for the starting angle of the arc drawn by Thread 2

When the timer in thread1 reaches the maximum value, it sets the bTimerIsUp flag to notify the other threads to exit.

Note: The example code shown in this document is for thread 1 in c_samplethread. The code for threads 2 and 3 is similar.

There is second IThread example application in Resources on the Brew MP Developer Network, c_samplethread_balls, which shows a more complex use of threads.

ZIP filename

Location

Run app

c_samplethread

Brew MP Resources

  • Download and extract the ZIP file.
  • Compile the app.
  • Run it on the Brew MP Simulator.
c_samplethread_balls

Running the sample code

When you run c_samplethread on the simulator or on a device, you can use the following keys to change the application behavior:

"1" - stop thread 1 when running

"2" - stop thread 2 when running

"3" - stop thread 3 when running

"select" - relaunch all threads if thread 1 has finished

"up" - speed up the moving arc (displayed by thread 2)

"down" - slow down the moving arc

"left" - increase the size of the arc

"right" - decrease the size of the arc