This is my application that is written in C,I write the main code till now. this app is an elevator that goes up and down in a 4 floors building:<br><br><br>#include<stdio.h><br>#include<stdlib.h><br>#include<string.h><br>
#include<stdbool.h><br>#include<time.h><br>#include <sys/time.h><br>#include <sys/types.h> <br>#include <unistd.h><br><br> <br>#include <signal.h> <br> <br>void handler(int signo) <br>{ <br>
  return; <br>} <br> <br><br>typedef struct person prs; <br>int elevator_run();       <br>struct person <br>{<br>    int place;<br>    int distination;<br>    char direction;<br>    bool inout;// in:true,out:false<br>    bool exit;//if person exits true<br>
    prs * next;<br>};<br>int stage[5];///////to know stop in which level<br>int up_down;///////to know direct  1 for up 0 for down  2 for none<br>int stop_move;/////to know if elevator is stop or no stop 0 move 1<br>int current_place;<br>
int distination; <br>time_t base;<br>int xx;<br>int main()<br>      {<br>    int place;<br>    int direct;<br>    int counter_in=0;<br>    int counter_out=0;<br>    int in_out;////in=1;out=0<br>    int dis;///to get distination of person in elevator<br>
    prs* headin;<br>    prs* headout;<br>    prs*newnode;<br>    prs*nextnode;<br>    prs*node;<br>    headin=(prs*)malloc(sizeof(prs));<br>    headout=(prs*)malloc(sizeof(prs));<br>    pthread_t thread_id;<br><br>        pthread_create(&thread_id, NULL,  elevator_run, NULL); <br>
          struct sigaction sa; <br> <br>  sa.sa_handler = handler; <br>  sigemptyset(&sa.sa_mask); <br>  sa.sa_flags = 0; <br>  sigaction(SIGALRM, &sa, NULL); <br> <br>  <br> <br>    if(headin==NULL)<br>    {<br>        printf("\nError in memory allocation!\n ");<br>
        return 1;<br>    }<br>    if(headout==NULL)<br>    {<br>        printf("\nError in memory allocation!\n ");<br>        return 1;<br>    }<br>    int update;<br>    printf("This is elevator stopped at ground \n tell us your place and distination ");<br>
    while(1)<br>    {<br>        update=0;<br>        alarm(1); <br> <br>  if (scanf("%d", &in_out) == 1) <br>  { <br>    alarm(0); // cancel the alarm <br>  } <br>  else <br>  { <br>    continue;<br>  } <br>
         //   scanf("% d", & in_out);<br>       <br><br><br>        if (in_out==1)<br>        {<br>          scanf("%d",& dis);<br>              if(current_place==distination)<br>          {<br>
              update=1;<br>              distination=dis;<br>          }<br>              else if((up_down==1 && distination<dis) ||(up_down==0 && distination>dis))<br>              {<br>                  update=1;<br>
                  stage[distination]=1;<br>                distination=dis;<br>              }<br>              else if((up_down==1 && current_place<dis<distination) ||(up_down==0 && distination<dis<current_place))<br>
                       stage[dis]=1;<br>                    else <br>                    {<br>                       newnode=(prs*)malloc(sizeof(prs));<br>                       if(newnode==NULL)<br>                          {<br>
                        printf("\nError in memory allocation!\n ");<br>                        return 1;<br>                          }<br>                       counter_in++;<br>                       newnode->exit=false;<br>
                       newnode->distination=dis;<br>                          newnode->next=headin->next;<br>                          headin->next=newnode;<br>            <br>            }<br>           }      <br>
         else {  <br>            scanf("%d %d",& place,& direct);<br>            if(direct=='q')<br>            return 1;<br>        if(stop_move==0){<br>          distination = place;<br>          printf("/////");}<br>
          else {<br>        if(direct==up_down &&((up_down==1&& current_place<=place<=distination) ||(up_down==0&& current_place>=place>=distination)))<br>           stage[place]=1;<br>
        if(direct==up_down && ((up_down==1 && place > distination) || (up_down==0 && place < distination)))<br>           {<br>               stage[distination]=1;<br>               distination=place;<br>
               update=1;<br>           }<br>        else <br>         {<br>           newnode=(prs*)malloc(sizeof(prs));<br>           if(newnode==NULL)<br>             {<br>            printf("\nError in memory allocation!\n ");<br>
            return 1;<br>         }<br>           counter_out++;<br>           newnode->exit=false;<br>           newnode->next=headin->next;<br>           headin->next=newnode;<br>           newnode->place=place;<br>
         }<br>           <br>          }<br>          }<br>    }<br>}<br><br><br>int elevator_run()<br>{<br>   <br>   time_t current;<br>   int i;<br>   int y=0;<br>   //float x=1;<br>   for(i=0;i<5;i++)<br>   stage[i]=0;<br>
   up_down=1;<br>   stop_move=0;/////to know if elevator is stop or no<br>   current_place=0;<br>   distination=0;<br><br>   while(1)<br>   {<br>     <br>      if(stop_move==1)<br>      {<br>        if(up_down==1)<br>    {<br>
      <br>      current=time(NULL);<br>      <br>      if(current==base + 5)<br>      {<br>      base=current;<br>      y=y+1;<br>      }<br>    //  printf("y = %f" ,y);<br>      }<br>    else<br>     {<br>     current=time(NULL);<br>
     <br>     if(current==base + 5)<br>      {<br>      base=current;<br>      y=y-1;<br>      }<br>    }<br>    }<br>    if(stop_move==0 && distination > current_place)<br>    {<br>        stop_move=1;<br>        base=time(NULL);<br>
        up_down=1;<br>        printf("salam");<br>    }<br>    if(stop_move==0 && distination < current_place)<br>    {<br>        stop_move=1;<br>        base=time(NULL);<br>        up_down=0;<br>    }<br>
      <br>      if(y == 0) {current_place=0;if(distination==0) stop_move=0;}<br>      if(y == 1 && current_place !=1) { printf("place1"); current_place=1; if(distination==1) stop_move=0;}<br>      if(y == 2 && current_place != 2) {current_place=2;printf("place2");if(distination==2) stop_move=0;}<br>
      if(y == 3 && current_place != 3) {current_place=3;printf("place3");if(distination==3) stop_move=0;}<br>      if(y == 4 && current_place != 4) {current_place=4;printf("place4");if(distination==4) stop_move=0;}<br>
      <br>   } <br>}<br><br><div class="gmail_quote">On Wed, Jul 18, 2012 at 8:11 PM, Till Straumann <span dir="ltr"><<a href="mailto:strauman@slac.stanford.edu" target="_blank">strauman@slac.stanford.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div>Maybe you could share some example code
      so that we understand<br>
      what exactly you're trying to do?<span class="HOEnZb"><font color="#888888"><br>
      <br>
      T.</font></span><div><div class="h5"><br>
      <br>
      On 07/18/2012 10:37 AM, m.shahverdi wrote:<br>
    </div></div></div><div><div class="h5">
    <blockquote type="cite">These two threads have some common fields that I use
      mutex on these fields but in general I read in c_user document of
      RTEMS that this OS has a flat memory and I'm worry about unsafe
      access to memory that each thread allocate in the beginning of
      execution.<br>
      <br>
      <div class="gmail_quote">On Wed, Jul 18, 2012 at 7:42 PM, Thomas
        Doerfler <span dir="ltr"><<a href="mailto:Thomas.Doerfler@embedded-brains.de" target="_blank">Thomas.Doerfler@embedded-brains.de</a>></span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
          <br>
          funny topic: one question, many different answers, none of
          them is<br>
          wrong ;-)<br>
          <br>
          Maybe you can specify, what you expect from a "memory
          protection"<br>
          mechanism:<br>
          - A way to synchronize two threads, so only one is allowed to<br>
          access/write to a memory area?<br>
          - A way to detect, when a thread inadvertedly tries to
          access/write to<br>
          another thread's private area?<br>
          - Something different?<br>
          <div><br>
            wkr,<br>
            <br>
            Thomas.<br>
            <br>
            Am 18.07.2012 16:20, schrieb m.shahverdi:<br>
          </div>
          <div>> Hi, I have an application with two
            threads but I don't know how to<br>
            > protect memory of each thread against other
            thread.please help me.<br>
            ><br>
            > thanks<br>
            ><br>
            ><br>
            ><br>
          </div>
          <div>>
            _______________________________________________ rtems-users
            mailing<br>
            > list <a href="mailto:rtems-users@rtems.org" target="_blank">rtems-users@rtems.org</a><br>
            > <a href="http://www.rtems.org/mailman/listinfo/rtems-users" target="_blank">http://www.rtems.org/mailman/listinfo/rtems-users</a><br>
            ><br>
            <br>
            <br>
            --<br>
          </div>
          IMD Ingenieurbuero fuer Microcomputertechnik<br>
          Thomas Doerfler           Herbststrasse 8<br>
          D-82178 Puchheim          Germany<br>
          email:    <a href="mailto:Thomas.Doerfler@imd-systems.de" target="_blank">Thomas.Doerfler@imd-systems.de</a><br>
          PGP public key available on request<br>
          <div><br>
            <br>
            --<br>
            --------------------------------------------<br>
            embedded brains GmbH<br>
            Thomas Doerfler<br>
            Obere Lagerstrasse 30<br>
            D-82178 Puchheim<br>
            Germany<br>
            email: <a href="mailto:Thomas.Doerfler@embedded-brains.de" target="_blank">Thomas.Doerfler@embedded-brains.de</a><br>
            Phone: +49-89-18908079-2<br>
            Fax: +49-89-18908079-9<br>
            PGP: Public key available on request.<br>
            <br>
            Diese Nachricht ist keine geschäftliche Mitteilung im Sinne
            des EHUG.<br>
            <br>
          </div>
          <div>
            <div>_______________________________________________<br>
              rtems-users mailing list<br>
              <a href="mailto:rtems-users@rtems.org" target="_blank">rtems-users@rtems.org</a><br>
              <a href="http://www.rtems.org/mailman/listinfo/rtems-users" target="_blank">http://www.rtems.org/mailman/listinfo/rtems-users</a><br>
            </div>
          </div>
        </blockquote>
      </div>
      <br>
      <br clear="all">
      <br>
      -- <br>
      <p align="right"><font size="3"><span lang="FA">به "هوالحی" زنده
            می کند؛</span></font></p>
      <p style="margin:0in 0in 10pt;text-align:right;direction:rtl" dir="RTL">
        <span lang="FA"><font size="3">آنسان که می میراند به
            "هوالممیت"..</font></span></p>
      <p style="margin:0in 0in 10pt;text-align:right;direction:rtl" dir="RTL"><span lang="FA"><font size="3">ما را به "هوالشهید" است
            که مدام می
            میراند و زنده می کند..</font></span></p>
      <p align="right"><font face="Times New Roman" size="3">
        </font></p>
      <br>
    </blockquote>
    <br>
    <br>
  </div></div></div>

</blockquote></div><br><br clear="all"><br>-- <br><p align="right"><font size="3"><span lang="FA">به "هوالحی" زنده می کند؛</span></font></p><p style="margin:0in 0in 10pt;text-align:right;direction:rtl" dir="RTL">
<span lang="FA"><font size="3">آنسان که می میراند به "هوالممیت"..</font></span></p><p style="margin:0in 0in 10pt;text-align:right;direction:rtl" dir="RTL"><span lang="FA"><font size="3">ما را به "هوالشهید" است که مدام می
میراند و زنده می کند..</font></span></p><p align="right"><font face="Times New Roman" size="3">

</font></p><br>