Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Threads #104

Closed
wants to merge 5 commits into
from

Conversation

2 participants
  1. Currently, when Thread wakes on timeout, it could not remove itself from ConditionVariable waiters until it acquires lock.
    So that, when ConditionVariable#signal is called, it will try to wakeup
    such thread, instead of some one else.

Simple way to avoid it, is to allow Mutex#sleep to recieve a block, which will be called right after Thread will awake, but before Mutex will be tried to lock

  1. Since MatzRuby use GVL for thread isolation, and native method could not be interrupted (unless it wish), we could remove couple of calles to Mutex#synchronize
  2. Usage of hash with compare_by_identity allows remove call to Array#include? in a Queue. Also it allows to remove other call Mutex#synchronize from ConditionVariable#wait in case when we rely on GVL.
  3. And cosmetic changes to SizedQueue

funny-falcon added some commits Sep 14, 2012

test_thread: add failing test for condvar.wait timeout
Thread, which call ConditionVariable#wait with timeout, could
not remove itself from waiters until it acquires lock on mutex.
So that, ConditionVariable#signal will try to wakeup already
awoken thread instead of one still waiting for a signal.
While user should not rely on this timeouts when he calls
#signal, I still think it is better to fix it.
* thread.c : add Mutex#sleep ability to accept block to run before lock
To fix case with ConditionVariable#wait timeout, simplest way is to
remove thread from sleepers before acquiring lock on mutex. To do
it, we should extend Mutex#sleep method to have ability accept block
and run it before trying to lock.
Perhaps, it is not the best way to do thing, but the simplest one.
thread.rb: cosmetic changes
One semantic difference:
 previously in SizedQueue#max= were used Thread#run outside of @mutex.synchronize
 now Thread#wakeup is called inside of @mutex.synchronize, as in SizedQueue#pop
I think, it is not big deal.
Member

zzak commented Nov 18, 2012

Please refer to Feature #7390 on redmine, thank you!

@zzak zzak closed this Nov 18, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment