I think what would work is declaring some number of mutexes, in array like 
48. Then you can compute CRC32 of the token, and lock based on modulo. But 
yes, probably best would be to change underlying code and just partitioning 
the work by hash.

const concurrency = 48


type concurrentChecks struct {

        mutex [concurrency]sync.Mutex

}


func (c *concurrentChecks) addCheck(token string) {

        mutex_num := crc32.ChecksumIEEE([]byte(token)) % concurrency

        c.mutex[mutex_num].Lock()

}


func (c *concurrentChecks) removeCheck(token string) {

        mutex_num := crc32.ChecksumIEEE([]byte(token)) % concurrency

        c.mutex[mutex_num].Unlock()

}

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e4df25db-28e9-4ffb-aacd-b290d6295e1d%40googlegroups.com.

Reply via email to