Home arrow Information arrow Getting Started
User Login
Main Menu
Latest Downloads
File Icon Hybridthreads Compiler: Generation of Application Specific Hardware Thread Cores from C (441)
File Icon Supporting High Level Language Semantics Within Hardware Resident Threads (821)
File Icon RCC Project: Investigating the Feasibility of FPGA-Based Petascale Computing (714)
File Icon Memory Hierarchy for MCSoPC Multithreaded Systems (874)
File Icon htc_v1_setup (167)
Hthreads Getting Started PDF Print E-mail
Written by Wesley Peck   
Tuesday, 01 August 2006

Using Hybridthreads

Because the Hthreads API is designed to be POSIX Threads compatible programming for the Hthreads system is much like programming with the pthreads library. Just like the pthreads library, programs written in the Hthreads system consists of multiple threads of control running in the same address space and controlled through syncrhonization primitives.

Creating Software Threads

The creation of software threads in the Hthreads system is almost exactly like the creation of threads in the pthreads library, and it is often very easy to convert existing pthreads programs into software only Hthreads programs.

Initialization

The first step in the creation of any Hthreads program is to include the top level Hthreads header file which provide the definitions of all of the functions available to Hthreads programs. Once this header file has been included the Hthreads program that you are writing will have access to all of the Hthreads functionality. An example of this is shown below.

// Include the Hybridthread header file so that
// Hybridthread functions are properly defined
#include

int main(int argc, char *argv[])
{
	// All of the functionality in the Hthreads 
	// system is available for use
} 

Creating More Threads

Often the first thing done in a multithreaded program is to create a set of children threads to run. In the Hthreads system this is done with calls to the hthread_create function. This function take four parameters; two are optional and two are required.

  • A Pointer to Thread ID Structure (Required)
  • A Pointer to Thread Attribute Structure (Optional)
  • A Pointer to Start Function (Required)
  • A Pointer to Arbitrary Paramter (Optional)

An example of a Hthreads program which creates several children threads is shown below.
// Include the Hybridthread header file so that
// Hybridthread functions are properly defined
#include

void* hello_thread( void *arg )
{
        printf( "Hello, World\n" );
        return NULL;
}

int main(int argc, char *argv[])
{
        // Declare a thread id structure which will hold the
        // thread id created by the call to hthread_create
        hthread_t tid;

        // Initialize the Hybridthreads System.
        // This should be the first function call in main
        hthread_init();

        // Create the hello world thread. The thread is
        // automatically scheduled to run when it is first created
        hthread_create( &tid, NULL, hello_thread, NULL );

        // Wait for the newly created thread to run and exit.
        // This is required if the program is going to run correctly.
        hthread_join( &tid, NULL );

        // Return status of the program
        return 0;
}

Last Updated ( Wednesday, 02 August 2006 )
 
© 2008 HThreads
Joomla! is Free Software released under the GNU/GPL License.