To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2549
2548  |  2550
Subject: 
Re: semaphores
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Fri, 10 May 2002 04:12:45 GMT
Viewed: 
5504 times
  
Would it be possible for you to send the entire source?  I would like to see
how it interacts with the rest of the program.


Thanks for your help.


"kenneth johansen" <kennethj@stud.cs.uit.no> wrote in message
news:3CDAC372.34D72C5C@stud.cs.uit.no...
> a short example:
> #include <semaphore.h>       // for semaphore opperations
> 
> 
> // global buffer, used to store incoming messages.
> // the buffer is checked by the application waiting for the message.
> struct inn_msg{
>   char *msg;
>   sem_t lock;
> };
> 
> //create a semaphora struct
> struct inn_msg *message;
> 
> // initiate the semaphora->lock to 0 (zero)
> sem_init(&message->lock,NULL,0);
> 
> 
> // process 1
> int process_1{){
> //whenever i copy something to message->msg i must update the
> message->msg = some memory _location;
> // update the semaphora
> sem_post(&message->lock);
> }
> 
> //process 2
> int process_2(){
> //wait for something to happend
> ret = sem_wait(&message->lock);
> //do something with message->msg
> }
> 
> after included the semahopra.h, creating a semaphora
> and initializing it, the idea here is that sem_post will increase
> message->lock by 1. the process doing the sem_wait will wait for
> message->lock to be nonzero before it starts executing further.
> this is how access to shared memory can be handled.
> 
> hope this helps, if not, lemme know :)
> 
> kenneth
> 
> 
> 
> Samuel Winchenbach wrote:
> 
> > Does anyone have any code that implements semaphores and shows where • they
> > might be useful?   That is one place that the documentation seems a • little
> > weak.  Thanks,
> > 
> > Sam
> 



Message is in Reply To:
  Re: semaphores
 
a short example: #include <semaphore.h> // for semaphore opperations // global buffer, used to store incoming messages. // the buffer is checked by the application waiting for the message. struct inn_msg{ char *msg; sem_t lock; }; //create a (...) (24 years ago, 9-May-02, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR