FAQ
Right now it seems if a lock is done before setting a value in a map then
it seems the entire map is locked preventing write to some other keys as
well.


mu.Lock()
x["string"] = "Hello"
mu.Unlock()



Is it possible to do a lock only at the key level(using any sync mechanism
or using some additional data-structure for keys) in any look-up data
structure so that writing to some other keys other than the one in which
lock is held can proceed without getting blocked?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Volker Dobler at Jun 29, 2015 at 11:27 am

    Am Montag, 29. Juni 2015 13:18:03 UTC+2 schrieb DM:
    Right now it seems if a lock is done before setting a value in a map then
    it seems the entire map is locked preventing write to some other keys as
    well.

    [...]Is it possible to do a lock only at the key level(using any sync
    mechanism or using some additional data-structure for keys) in any look-up
    data structure so that writing to some other keys other than the one in
    which lock is held can proceed without getting blocked?
    No it is not possible.

    V.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Matthew Zimmerman at Jun 29, 2015 at 11:59 am
    It's not possible exactly as you've described, but I've tackled this
    problem by splitting out the entities in the map with a hash %
    runtime.NumCPU()

    http://play.golang.org/p/c4yTgmcQHI

    This will use more memory, but now you should achieve almost 100 % cpu
    utilization even with a map based data structure storing the data.
    On Mon, Jun 29, 2015 at 7:28 AM Volker Dobler wrote:

    Am Montag, 29. Juni 2015 13:18:03 UTC+2 schrieb DM:
    Right now it seems if a lock is done before setting a value in a map then
    it seems the entire map is locked preventing write to some other keys as
    well.

    [...]Is it possible to do a lock only at the key level(using any sync
    mechanism or using some additional data-structure for keys) in any look-up
    data structure so that writing to some other keys other than the one in
    which lock is held can proceed without getting blocked?
    No it is not possible.

    V.

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Debraj Manna at Jun 30, 2015 at 4:31 am
    Thanks Volker and Matthew.
    On Mon, Jun 29, 2015 at 5:29 PM, Matthew Zimmerman wrote:

    It's not possible exactly as you've described, but I've tackled this
    problem by splitting out the entities in the map with a hash %
    runtime.NumCPU()

    http://play.golang.org/p/c4yTgmcQHI

    This will use more memory, but now you should achieve almost 100 % cpu
    utilization even with a map based data structure storing the data.
    On Mon, Jun 29, 2015 at 7:28 AM Volker Dobler wrote:

    Am Montag, 29. Juni 2015 13:18:03 UTC+2 schrieb DM:
    Right now it seems if a lock is done before setting a value in a map
    then it seems the entire map is locked preventing write to some other keys
    as well.

    [...]Is it possible to do a lock only at the key level(using any sync
    mechanism or using some additional data-structure for keys) in any look-up
    data structure so that writing to some other keys other than the one in
    which lock is held can proceed without getting blocked?
    No it is not possible.

    V.

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to a topic in the
    Google Groups "golang-nuts" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/golang-nuts/0XQpzO3obdc/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to
    golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Haddock at Jun 30, 2015 at 5:17 am
    You can create a segmented map. You can look at class ConcurrentHashMap in Java for this. It has 256 segments if I recall correctly. Problem is iterating over the entire map or querying the size. Then you still have to lock all segments. So your code whould avoid to do this.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 29, '15 at 11:18a
activeJun 30, '15 at 5:17a
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase