From: Andrew Crabtree Message-Id: <199706241550.AA012077402@typhoon.rose.hp.com> Subject: Re: I need help!!! To: darkstar AT user1 DOT channel1 DOT com Date: Tue, 24 Jun 1997 8:50:02 PDT Cc: djgpp AT delorie DOT com In-Reply-To: <33AC6429.3B57@user1.channel1.com>; from "darkstar@user1.channel1.com" at Jun 21, 97 4:30 pm Precedence: bulk > > Ok, I would like to know how you "lock" a variable. Do you mean mutex semaphores? You have to use assembly. > Could > someone give me an example? The following assembly is the shortest, though very non-ideal semaphore routine getsem : lock bts Reg1,Reg2; try to get the semaphore jc getsem ; if we didn't get it try again This does a busy wait. If you want it to be C Callable you will have to inline it or get a param off of the stack. You will also need a free routine which should be simple to write. To use it you just declare a global variable to be you sempahore and then call getsem when you want it. Your call will block until the sem becomes available so you better have either a pre-emptive system or an ISR that changes it. Note that typically your OS will provide functions like this if it supports them. It will usually put your task on a non-ready queue until the sem becomes available and let other processes run. I probably should have checked DJ libc to see if he has support for semaphores already (duh!) before I wrote this, but I didn't. Maybe browse through the posix stuff... > Also, does Djgpp use function variables? Do you mean function pointers? Sure. They are standard in C. instead of doing this int *ptr do this int (*fnctptr) ... ; HTH Andrew