title: Queues in TI-SYSBIOS
body: <p>I am trying to use Queues in my project. Below is a simple example from TI.</p>
  
  <pre><code>void mailbox_queue(void)
  {
      MsgObj msg; // create an instance of MsgObj named msg
      Msg msgp;   // Queues pass POINTERS, so we need a pointer of type Msg
      msgp = &amp;msg;// init message pointer to address of msg
      msg.val = 1;// set initial value of msg.val (LED state)
  
      while(1){
          msg.val ^= 1; // toggle msg.val (LED state)
          Semaphore_pend(LEDSem, BIOS_WAIT_FOREVER);// wait on semaphore 
          Queue_put(queue0, (Queue_Elem*)msgp);   // pass pointer to Message 
          Semaphore_post (qMsgSem);       // unblock Queue_get to get msg
      }
  }
  
  Problem statement:
  </code></pre>
  
  <p>mailbox_queue task is pending on the semaphore LEDSem. Once this semaphore is posted, 
  I am placing the msg on Queue and post a semaphore to signal the receiver side.</p>
  
  <p>The issue i am running into is, while the msg object is local, even before the receiver
  gets the msg.val value, there is a high chance that msg.val could be written to a new value.
  Also, Cert-C strongly recommends not to pass the pointers of local variables or structs.</p>
  
  <p>One way i could solve this is to declare msg struct as static but this would make a copy which would 
  consume space on RAM.</p>
  
  <p>Can anyone help me solve this problem.</p>
  
  <p>Greatly appreciate that. </p>