<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello Fellow Litmus Devs,<div class=""><br class=""></div><div class="">In Litmus, each semaphore/mutex instance is uniquely identified by a (file name, object ID) tuple. To gain access to such an instance, a thread passes these parameters to Litmus. Litmus will create the semaphore/mutex instance if it does not already exist. Litmus then passes back a unique object descriptor that the thread can use in subsequent litmus_lock()/litmus_unlock() calls. </div><div class=""><br class=""></div><div class="">Currently, object descriptors CANNOT be shared between threads of the same process. Each thread must obtain its own object descriptor. I think an advantage to this approach is that it gives the locking protocol implementation an opportunity to dynamically allocate per-thread data structures or update the locks state. However, I’m wondering if this is more trouble than it’s worth. Has anyone implemented a locking protocol that required dynamically allocated per-thread data? Would this be used in PCP/SRP to dynamically maintain the priority ceiling of a resource?</div><div class=""><br class=""></div><div class="">Here is a concrete example of the trouble non-sharable object descriptors can cause. Suppose you want to create a C++11-styled mutex wrapper class with an FMLP-underpinning. Following the C++11 style, a single instance of the mutex class in a process should map to the same FMLP instance in Litmus. Unfortunately, the per-thread object descriptor requires the following cumbersome implementation:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #78492a" class="">#include </span><unordered_map></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(120, 73, 42);" class="">#include <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class=""><cstdint></span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #78492a" class="">#include </span><litmus.h></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class="">// A basic mutex interface</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class="">// (The real C++11 interface includes a try_lock(). UGH.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class="">// I guess any L.P. that doesn’t support try_lock() could</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class="">// always fail.)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> mutex</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">{</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class="">private<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> mutex(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span> mutex&) = <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">delete</span>;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> mutex& <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">operator</span>=(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span> mutex&) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">delete</span>;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> mutex(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span>) = <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">default</span>;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>virtual<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> ~mutex(</span>void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) = </span>default<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">;</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">virtual</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span> lock() = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">virtual</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span> unlock() = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">};</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class="">// FMLP with mutex interface</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> fmlp_mutex: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> mutex</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">{</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>// takes an open file descriptor and a name (ID) for the FMLP instance</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> fmlp_mutex(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> _fd, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> _name):</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> mutex(),</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> fd(_fd), name(_name)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class=""> virtual<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> lock(</span>void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> litmus_lock(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">this</span>->descriptor());</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class=""> virtual<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> unlock(</span>void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> litmus_unlock(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">this</span>->descriptor());</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> open(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span>)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> desc = -<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> uint64_t key = fd;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> key = (key << <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">32</span>) | name;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span>(unlikely(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nullptr</span> == descriptorMap))</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> descriptorMap = <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">new</span> std::unordered_map<uint64_t, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span>>();</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">auto</span> search = descriptorMap->find(key);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span>(search != descriptorMap->end())</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> desc = search->second;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> new_desc = open_fmlp_sem(fd, name);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span>(new_desc < <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> fprintf(stderr, </span>"Failed to create FMLP mutex with ID %d\n"<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">,</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> name);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> exit(-<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> descriptorMap->insert(std::make_pair(key, new_desc));</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> desc = new_desc;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> desc;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>// returns the per-thread FMLP instance object descriptor</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> descriptor(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">void</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span>(unlikely(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nullptr</span> == descriptorMap))</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> -<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> uint64_t key = fd;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> key = (key << <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">32</span>) | name;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">auto</span> search = descriptorMap->find(key);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span>(likely(search != descriptorMap->end()))</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> search->second;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> -<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span> uint32_t fd;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span> uint32_t name;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class="">protected<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">virtual</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> open_type(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> fd, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> name) = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class="">protected<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">__thread</span> std::unordered_map<uint64_t, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span>>* descriptorMap;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">};</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><span style="color: rgb(0, 132, 0);" class="">// vvv Put the below in some .cpp file somewhere vvv</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">__thread</span> std::unordered_map<uint64_t, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span>>* fmlp_mutex::descriptorMap = <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nullptr</span>;</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">What is cumbersome about the above implementation? The use of thread-local storage (<span style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;" class="">__thread</span>) to maintain a mapping of (file name, object ID)-tuples to FMLP object descriptors</div><div class=""><br class=""></div><div class="">Before a thread may use the fmlp_mutex instance, it must first call “fmpl_instance->open().” Then, every lock/unlock call requires a lookup of the object descriptor. It’s branchy. It’s on the fast-path. (Things get more complicated if we want to properly close descriptors, but I’ve left that code out.)</div><div class=""><br class=""></div><div class="">However, all this goes away if we can share object descriptors among threads of the same process:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class="">// Implementation is GREATLY simplified if object descriptors can be shared</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class="">// among threads of the same process.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> fmlp_simple_mutex: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> mutex</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">{</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>// takes an open file descriptor and a name (ID) for the FMLP instance</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> fmlp_simple_mutex(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> _fd, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">int</span> _name):</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> mutex(),</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> fd(_fd), name(_name)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> desc = open_fmlp_sem(fd, name);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span>(desc < <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> fprintf(stderr, </span>"Failed to create FMLP mutex with ID %d\n"<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">,</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> name);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> exit(-<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>);</div><div style="margin: 0px;" class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><font face="Menlo" class=""><span style="font-size: 11px;" class=""> </span></font></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class=""> virtual<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> lock(</span>void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> litmus_lock(desc);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class=""> virtual<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> unlock(</span>void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> {</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> litmus_unlock(desc);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span> uint32_t fd;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">const</span> uint32_t name;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(187, 44, 162);" class="">protected<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""> int32_t desc;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">};</div></div><div class=""><br class=""></div><div class="">By allowing object descriptors to be shared, we’ve lost the ability to notify the underlying locking protocol instance that there is a new user of the object. However, we can still support this with an additional system call. A thread would pass an object descriptor to the system call and Litmus would make the necessary updates. To me, this seems less-bad than the thread-local storage hoops we have to jump through with Litmus’s current way of doing things. You may still need a complicated implementation like I have above for fmlp_mutex for locking protocols that require the second system call. However, at least such complications would be limited to those locking protocols.</div><div class=""><br class=""></div><div class="">I don’t yet have the time to propose a patch to Litmus. Even if we decide to leave Litmus as-is, hopefully this email will spread awareness of how Litmus manages locks. At the very least, I would be interested in the thoughts of others on this.</div><div class=""><br class=""></div><div class="">-Glenn</div></body></html>