Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed race condition in RecycleBin. #1828

Merged

Conversation

emilwestergren
Copy link
Contributor

Replaced SynchronizedList with VectorList + Mutex to maintain thread safety.
@erikhagglund peer review

_size: Int
count ::= this _list count
isFull ::= this count == this _size
isEmpty ::= this _list empty
init: func (=_size, =_free) { this _list = SynchronizedList<T> new(_size) }
_mutex := Mutex new()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the count, isFull and isEmpty is not thread safe, change to private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, this class should be able to use without a mutex, then those properties should be public anyway.

@emilwestergren emilwestergren force-pushed the recyclebin_thread_safe_fix branch 2 times, most recently from 9106672 to 20aa5eb Compare July 5, 2016 17:40
result: T = null
(index > -1) ? this _list remove(index) : result
this _mutex lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastianbaginski Somewhere you changed to put result: T = null inside the lock, is that good as a general rule or was it a special case? I don't remember the specifics.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was here #1821 (comment)
Yes, it does matter for generics, because this line result: T = null can trigger the "constructor" of the Pointer_Class due to lazy initialization. This constructor can then modify a static bool flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Looks like it's being fixed, but won't make it to us any time soon I'm afraid. ooc-lang/rock#1004
In the mean time, @emilwestergren - move line 35 below line 36.

@marcusnaslund
Copy link
Contributor

This removes the only use of SynchronizedList... do we keep it?

@emilwestergren
Copy link
Contributor Author

I vote for keeping it.

@emilwestergren
Copy link
Contributor Author

Updated

@marcusnaslund marcusnaslund merged commit ee8e118 into magic-lang:develop Jul 6, 2016
@emilwestergren emilwestergren deleted the recyclebin_thread_safe_fix branch July 18, 2016 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants