<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">It means that there are no 'processes'
      as e.g., in unix.<br>
      Processes have independent address spaces and cannot<br>
      access each other's. Hence, there is no way for process 'A'<br>
      to overwrite and corrupt memory 'malloc()'ed by process 'B'.<br>
      <br>
      RTEMS is a 'single process' with multiple threads which are<br>
      assumed to collaborate (and not try to destroy each other).<br>
      <br>
      Threads under RTEMS behave like multiple threads in a<br>
      single unix program. All threads can access all of the memory<br>
      (and other resources).<br>
      <br>
      HTH<br>
      - T.<br>
      <br>
      <br>
      On 07/20/2012 06:14 AM, m.shahverdi wrote:<br>
    </div>
    <blockquote
cite="mid:CAJDSd-tt4GUs_39kGsRHLANH9NajJY8T09utKcjJSi5G4xn86A@mail.gmail.com"
      type="cite"><span class="Apple-style-span"
        style="color:rgb(0,0,0);font-family:tahoma,'new
york',times,serif;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);display:inline!important;float:none">According
        to RTEMS POSIX API User’s Guide</span><span
        style="background-color:rgb(255,255,255);color:rgb(0,0,0)"> "</span><span
        class="Apple-style-span"
        style="color:rgb(0,0,0);font-family:tahoma,'new
york',times,serif;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);display:inline!important;float:none">RTEMS
        provides no memory protection"! so what does this</span><span
        style="background-color:rgb(255,255,255);color:rgb(0,0,0)">
        mean?</span><br>
      <br>
      <div class="gmail_quote">On Wed, Jul 18, 2012 at 8:46 PM, Gedare
        Bloom <span dir="ltr"><<a moz-do-not-send="true"
            href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</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>
          You are right to have some concern because your global
          variables will<br>
          need to be locked somehow (posix mutex/semaphore) since they
          are<br>
          accessed by both your 'main' task and the pthread that is
          created.<br>
          This is a correctness problem; without locking this program's
          behavior<br>
          is poorly defined I would guess. I assume that sharing the
          global<br>
          variables between 'main' and the spawned thread is the desired<br>
          behavior.<br>
          <span class="HOEnZb"><font color="#888888"><br>
              -Gedare<br>
            </font></span>
          <div class="HOEnZb">
            <div class="h5"><br>
              On Wed, Jul 18, 2012 at 11:58 AM, m.shahverdi <<a
                moz-do-not-send="true" href="mailto:sspardis2@gmail.com">sspardis2@gmail.com</a>>
              wrote:<br>
              > This is my application that is written in C,I write
              the main code till now.<br>
              > 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"Mosset, Robyn"
              <a class="moz-txt-link-rfc2396E" href="mailto:robyn@slac.stanford.edu"><robyn@slac.stanford.edu></a>"Mosset, Robyn"
              <a class="moz-txt-link-rfc2396E" href="mailto:robyn@slac.stanford.edu"><robyn@slac.stanford.edu></a><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<br>
              > 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 &&<br>
              > distination>dis))<br>
              >               {<br>
              >                   update=1;<br>
              >                   stage[distination]=1;<br>
              >                 distination=dis;<br>
              >               }<br>
              >               else if((up_down==1 &&
              current_place<dis<distination)<br>
              > ||(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&&<br>
              > current_place<=place<=distination)
              ||(up_down==0&&<br>
              > current_place>=place>=distination)))<br>
              >            stage[place]=1;<br>
              >         if(direct==up_down && ((up_down==1
              && place > distination) ||<br>
              > (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;<br>
              > if(distination==1) stop_move=0;}<br>
              >       if(y == 2 && current_place != 2)<br>
              > {current_place=2;printf("place2");if(distination==2)
              stop_move=0;}<br>
              >       if(y == 3 && current_place != 3)<br>
              > {current_place=3;printf("place3");if(distination==3)
              stop_move=0;}<br>
              >       if(y == 4 && current_place != 4)<br>
              > {current_place=4;printf("place4");if(distination==4)
              stop_move=0;}<br>
              ><br>
              ><br>
              >    }<br>
              > }<br>
              ><br>
              > On Wed, Jul 18, 2012 at 8:11 PM, Till Straumann <<a
                moz-do-not-send="true"
                href="mailto:strauman@slac.stanford.edu">strauman@slac.stanford.edu</a>><br>
              > wrote:<br>
              >><br>
              >> Maybe you could share some example code so that
              we understand<br>
              >> what exactly you're trying to do?<br>
              >><br>
              >> T.<br>
              >><br>
              >><br>
              >> On 07/18/2012 10:37 AM, m.shahverdi wrote:<br>
              >><br>
              >> These two threads have some common fields that I
              use mutex on these fields<br>
              >> but in general I read in c_user document of RTEMS
              that this OS has a flat<br>
              >> memory and I'm worry about unsafe access to
              memory that each thread allocate<br>
              >> in the beginning of execution.<br>
              >><br>
              >> On Wed, Jul 18, 2012 at 7:42 PM, Thomas Doerfler<br>
              >> <<a moz-do-not-send="true"
                href="mailto:Thomas.Doerfler@embedded-brains.de">Thomas.Doerfler@embedded-brains.de</a>>
              wrote:<br>
              >>><br>
              >>> 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>
              >>><br>
              >>> wkr,<br>
              >>><br>
              >>> Thomas.<br>
              >>><br>
              >>> Am 18.07.2012 16:20, schrieb m.shahverdi:<br>
              >>> > 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>
              >>> >
              _______________________________________________
              rtems-users mailing<br>
              >>> > list <a moz-do-not-send="true"
                href="mailto:rtems-users@rtems.org">rtems-users@rtems.org</a><br>
              >>> > <a moz-do-not-send="true"
                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>
              >>> IMD Ingenieurbuero fuer Microcomputertechnik<br>
              >>> Thomas Doerfler           Herbststrasse 8<br>
              >>> D-82178 Puchheim          Germany<br>
              >>> email:    <a moz-do-not-send="true"
                href="mailto:Thomas.Doerfler@imd-systems.de">Thomas.Doerfler@imd-systems.de</a><br>
              >>> PGP public key available on request<br>
              >>><br>
              >>><br>
              >>> --<br>
              >>> --------------------------------------------<br>
              >>> embedded brains GmbH<br>
              >>> Thomas Doerfler<br>
              >>> Obere Lagerstrasse 30<br>
              >>> D-82178 Puchheim<br>
              >>> Germany<br>
              >>> email: <a moz-do-not-send="true"
                href="mailto:Thomas.Doerfler@embedded-brains.de">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>
              >>>
              _______________________________________________<br>
              >>> rtems-users mailing list<br>
              >>> <a moz-do-not-send="true"
                href="mailto:rtems-users@rtems.org">rtems-users@rtems.org</a><br>
              >>> <a moz-do-not-send="true"
                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>
              >> --<br>
              >><br>
              >> به "هوالحی" زنده می کند؛<br>
              >><br>
              >> آنسان که می میراند به "هوالممیت"..<br>
              >><br>
              >> ما را به "هوالشهید" است که مدام می میراند و زنده
              می کند..<br>
              >><br>
              >><br>
              >><br>
              >><br>
              ><br>
              ><br>
              ><br>
              > --<br>
              ><br>
              > به "هوالحی" زنده می کند؛<br>
              ><br>
              > آنسان که می میراند به "هوالممیت"..<br>
              ><br>
              > ما را به "هوالشهید" است که مدام می میراند و زنده می
              کند..<br>
              ><br>
              ><br>
              ><br>
              > _______________________________________________<br>
              > rtems-users mailing list<br>
              > <a moz-do-not-send="true"
                href="mailto:rtems-users@rtems.org">rtems-users@rtems.org</a><br>
              > <a moz-do-not-send="true"
                href="http://www.rtems.org/mailman/listinfo/rtems-users"
                target="_blank">http://www.rtems.org/mailman/listinfo/rtems-users</a><br>
              ><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>
  </body>
</html>