Skip to content

Conversation

@mihacooper
Copy link
Member

@mihacooper mihacooper commented Jan 14, 2019

Please take a look at this proposal. It works like that:

local m = effil.mutex()

m:unique_lock(function()
    -- write
end)

m:shared_lock(function()
    -- read
end)

if not m:try_unique_lock(function() 
    -- ok, you can write
end) then
    -- it's busy right now
end

if not m:try_shared_lock(function() 
    -- ok, you can read
end) then
    -- it's busy right now
end

@IUdalov
Copy link
Contributor

IUdalov commented Jan 17, 2019

1.
Why not to add this methods to mutex itself.

local m = effil.mutex()
m:unique_lock(function()
  -- 
end)

2. Idiom for this is synchronized.
https://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html

3. Can we add regular C'like mutex?

@mihacooper
Copy link
Member Author

1.
Why not to add this methods to mutex itself.

Yes, it's a good idea

2. Idiom for this is synchronized.
https://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html

I don't get what you mean

3. Can we add regular C'like mutex?

Instead of this implementation or in addition to?

@IUdalov
Copy link
Contributor

IUdalov commented Jan 17, 2019

Rename this stuff from unique_lock to synchronized or something like it.
And add regular mutex, shared mutex and conditional variable.

@mihacooper
Copy link
Member Author

We don't really need regular mutex if we have shared mutex (just use unique lock). If we have two types of locks 'shared' and 'unique' then 'synchronized' is not really good option.

Condition variable is a good idea too, but it can be implemented separately.

@SaintMercury
Copy link

Is there still a desire to merge this? defined mutex would be nice as opposed to just using channel

@mihacooper
Copy link
Member Author

closes #171

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants