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 / 2545
2544  |  2546
Subject: 
Re: semaphores
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 9 May 2002 18:44:02 GMT
Viewed: 
2421 times
  
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 has 1 Reply:
  Re: semaphores
 
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.34D72C....uit.no... (...) (...) (23 years ago, 10-May-02, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  semaphores
 
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 (23 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

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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