Status of multithreaded code

Ben Hartshorne memcache at
Sat May 26 01:01:45 UTC 2007


I saw a --enable-threads option in the configure script, along with a
thredas.c that contained multithreaded code.

What is the status of this code?  

I was looking at the code for mt_item_get_nocheck to get an item
regardless of its deleted status.

    392 /*
    393  * Returns an item whether or not it's been marked as expired or deleted.
    394  */
    395 item *mt_item_get_nocheck(char *key, size_t nkey) {
    396     item *it;
    398     pthread_mutex_lock(&cache_lock);
    399     it = assoc_find(key, nkey);
    400     it->refcount++;
    401     pthread_mutex_unlock(&cache_lock);
    402     return it;
    403 }

If assoc_find returns 0 (which it does if the item is a cache miss), it
looks to me as though the function will segfault when it tries to
derefernce it in line 400.


The corresponding single-threaded function checks to make sure it is
valid before derefencing it:

    402 /* returns an item whether or not it's delete-locked or expired. */
    403 item *do_item_get_nocheck(const char *key, const size_t nkey) {
    404     item *it = assoc_find(key, nkey);
    405     if (it) {
    406         it->refcount++;
    407         DEBUG_REFCNT(it, '+');
    408     }
    409     return it;
    410 }


Ben Hartshorne
email: ben at
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url :

More information about the memcached mailing list