[RFC] "lock" statement and "mutex" type.

BCS BCS_member at pathlink.com
Tue Mar 14 15:31:14 PST 2006


The simple tryLock would allow for timeout:

while(!timeout())
{
   lock(mutex)
   {
     go();
     break;
   }
   else
     continue;
}

A bit clunky but...

I'm glad that native support for threads is being considered, I think that it 
would be a vary good thing. It would allow for some quite nice features like:

thread t1;

t1.run = &fn;	// launch thread

if(t1mustDie) t1.throw new KillThread;	// throw an exception in t1



Dejan Lekic wrote:
> Hi Sean,
> yes, i did not think about acquisition with a timeout maybe following syntax
> change is what we would like to have:
> lock (<mutex variable>[, timeout]) 
> 
> You understood everything else. My was plain simple trylock. Following code
> is an example of code without try:
> 
> lock (myMutex) // blocks calling thread
> {
>   doSomething();
> }
> 
> as we slightly changed the main idea (from my previous post), we could have
> something like:
> 
> lock (myMutex, 1000) // blocks calling thread for 1 second
> {                    // if mutex "myMutex" is not unlocked during that time
>   doSomething();     // it will exit the lock() block and execute continue()
> }                    // function.
> continue();
> 
> 
> Regards
> 
> -----------
> Dejan Lekic
>   http://dejan.lekic.org



More information about the Digitalmars-d mailing list