Yii Framework Forum: [EXTENSION] Mutex - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] Mutex Rate Topic: -----

#1 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 29 March 2010 - 04:27 PM

For discussion/bugtracking about the extension.
0

#2 User is online   Raoul 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 598
  • Joined: 29-November 08
  • Location:Paris, France

Posted 12 April 2010 - 04:24 PM

Hi Y!!,
I've downloaded your EMutex extension, and I have a question on how it works. Really, I didn't notice any problem, that's just I would like to understand better the basic principles of your mutex.
I'm probable wrong but it seems to me that in a particular case, 2 php threads could get the same mutex.
On the lock method, you wrote :

file_put_contents($path, serialize(array($timeout, time())), LOCK_EX);


This is the only command that is garanteed to be atomic right ? Then, 2 php threads could execute all previous lines, and reach this one sequencially .. isn't it ?

Thread 1> if (false !== $data && (0 === $data[0] || $data[0] + $data[1] > time()))
Thread 2> if (false !== $data && (0 === $data[0] || $data[0] + $data[1] > time()))

Thread 2 > array_push($this->_locks, $id);
Thread 1 > array_push($this->_locks, $id);

Thread 1 > file_put_contents($path, serialize(array($timeout, time())), LOCK_EX);
Thread 2 > file_put_contents($path, serialize(array($timeout, time())), LOCK_EX);

// both thread have the mutex !!


Of course, that is very bad luck, but from a formal point of view, this is possible no ?
Please, could you tell me if and why I'm wrong ...
thanks
B)
0

#3 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 12 April 2010 - 06:00 PM

Hehe good find. Yes I think it's possible. Though, under some crazy circumstances since the time-difference between checking and writing the lock file is probably under 3ms. I'm not really sure yet what a good fix would be, probably the use of flock() with only one global lock file (that hold's all locks in a serialized array)?
0

#4 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 13 April 2010 - 06:48 AM

I updated the extension.

- All locks in one file
- Now using microtime() for more precise timeout
- Some other enhancements
0

#5 User is online   Raoul 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 598
  • Joined: 29-November 08
  • Location:Paris, France

Posted 13 April 2010 - 04:01 PM

that it greay Y!! .. As I told you, I never had any problem with EMutex, my question was just theorical, but I apreciate you new enhancments and this time, it seems that there can't be any Mutex 'collision' ...even theorically ;)
Thanks
ciao
B)
0

#6 User is offline   jptsetung 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-March 10

Posted 06 March 2012 - 05:55 AM

That's an awesoem extension, exactly what I was looking for. Thx!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users