Thread: problem with struct?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    14

    problem with struct?

    It seems that there is some problem with struct TCB
    but I cannot find out what's wrong with it.
    Please help!
    Thank you very much!

    The head file is the following:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Code:
    #ifndef UTHREAD_H 
    #define UTHREAD_H 
    
    #include <stdio.h> 
    #include <ucontext.h> 
    #include <semaphore.h> 
    #include <unistd.h> 
    #include <stdlib.h> 
    #include <errno.h> 
    #include <signal.h> 
    #include <sys/time.h> 
    
    /* you might find some of these definitions helpful */ 
    #define THR_QUANTUM_DEFAULT 5 /* default time quantum ms */ 
    #define THR_STACK_DEFAULT 65536 /* default stack bytes */ 
    #define THR_FAILURE -1 /* unable to create thread */ 
    #define THR_NOSUCHTHREAD -1 /* bad access to thread */ 
    #define MAX_JOIN_NUM 100 //maximum joinalbe number of thread 
    #define MILLION 1000000L    //convert sec to msec 
    
    #ifdef __CPLUS_PLUS__ 
    // C++:  Provide C linkages 
    namespace "std" { 
      extern "C" { 
    #endif 
    
        typedef int ThreadId_t; 
    
        /* thread states */ 
        typedef enum { 
          BLOCKED, /* blocked */ 
          RUNNING, /* currently dispatched */ 
          READY, /* in ready queue */ 
          COMPLETED, /* returned from thread */ 
          KILLED, /* killed by another thread 
    * (you don't need to implement this one) 
    */ 
        } ThreadState_t; 
    
    typedef enum { 
          THR_QUIET, /* no information */ 
          THR_SWITCH, /* report thread switch */ 
          THR_SUMMARY /* provide the same information as in thr_summary */ 
        } thr_diagnostic_t; 
      
        /* Thread control block 
        * Add to this structure as you see fit, but you may not 
        * change the name 
        */ 
        typedef struct { 
          ThreadId_t  id; /* unique identifier */ 
          ThreadState_t state; 
      ucontext_t context; //record context 
      void *result; //record final result 
      ThreadId_t j[MAX_JOIN_NUM]; //maxinum number of joinable thread for thr_join 
      int acn; //record the active number of thread 
      struct timeval exest; //record start of exe time 
      struct timeval exendt; //record end of exe time 
      struct timeval qust; //record start time in READY queue 
      long qtime; //record end time in READY queue 
      thr_diagnostic_t debug; //set debug 
      double acw; //average context switch time 
    58   TCB *next; 
        } TCB; 
    
    TCB *head; 
    
    
    64    void thr_init(); /* Initialize thread package */ 
        
    65    void thr_quantum(int N_ms);   /* Set time quantum to N ms */ 
    
    66    ThreadId_t thr_create(void * (*start_fn)(void *), void *arg); 
    
    67    void thr_exit(void *result); 
    
    68    int thr_join(ThreadId_t id, void **result); 
    
    69    void thr_diagnostics(thr_diagnostic_t Verbosity); 
    
    70    void thr_summary(FILE *FileHandle); 
    #ifdef __CPLUS_PLUS 
      } 
    } 
    #endif 
      
    #endif
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    thr_init.c is the following:

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Code:
    #include "uthread.h" 
    
    void thr_init() 
    { 
    // initiate thread queue 
    head = (TCB *)malloc(sizeof(TCB)); 
    head->next = NULL; 
    head->id = 0; 
    head->state = RUNNING; 
    head->result = NULL; 
    head->acn = 1; 
    head->qtime = 0; 
    
    。。。。。。。。。。。。。。 
    }
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    when I compile, the following problems always comes out:
    "thr_init.c", line 1: warning: invalid white space character in directive (why it is invalid?)
    "uthread.h", line 58: syntax error before or at: TCB
    "uthread.h", line 64: member cannot be function: thr_init
    "uthread.h", line 65: member cannot be function: thr_quantum
    "uthread.h", line 66: member cannot be function: thr_create
    "uthread.h", line 67: member cannot be function: thr_exit
    "uthread.h", line 68: member cannot be function: thr_join
    "uthread.h", line 69: member cannot be function: thr_diagnostics
    "uthread.h", line 70: member cannot be function: thr_summary
    Last edited by Salem; 09-27-2008 at 11:37 PM. Reason: THINK what the code tags message is telling you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Struct File and array problem Please help
    By theprogrammer in forum C Programming
    Replies: 17
    Last Post: 04-02-2009, 08:05 AM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  3. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  4. Replies: 22
    Last Post: 12-23-2008, 01:53 PM
  5. Replies: 16
    Last Post: 10-29-2006, 05:04 AM