On Sun, Mar 5, 2017 at 10:25 PM David Mertz <me...@gnosis.cx> wrote: > > Could we make the file global a table of comparison functions and have > each thread reference a position in the table? It would be fine if multiple > threads happened to use the position of e.g. the int comparison, just so > long as each chose the right slot in the table. >
I don't think that would solve anything. The problem is that the pre-sort check is carried out in the main sort function, but then lots of smaller functions need to know which compare to use. Since the scope isn't shared, then, how can we inform the smaller functions of which compare to use? I solved this problem by just putting the compare function pointer in global scope. Obviously, however, this is not thread-safe. So the question is, how can the smaller functions be made aware of the results of the pre-sort check? Your proposal would merely replace the problem of communicating the function pointer with the problem of communicating the appropriate index into the function table. The smaller functions wouldn't know which index they're supposed to use unless you passed it in. However, I believe the following *would* work: Suppose it were possible to access an identifier unique to each thread, such as that returned by gettid() on Linux. Then maintain a global table of (unique_thread_id, compare_func) pairs, and simply have the ISLT macro index into the table! A bit of a performance hit, sure, but hopefully not that bad? Certainly better than passing it in every time... the problem is, how can we get a unique identifier for the thread in a platform-independent way? Any ideas?
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/