<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>It is in C for portability. Like everything else.<BR> <BR> <BR>Otherwise you have to duplicate the C headers in Modula-3, and they end up being system specific because there are too many ways to turn the portable C source interface into non-portable ABI -- #defines, #pragmas, etc.<BR> <BR> <BR>For Linux I do at least use __thread instead of pthread_getspecific.<BR>I found __thread support too varying/missing to use otherwise.<BR> <BR> <BR><a href="http://modula3.elegosoft.com/cgi-bin/cvsweb.cgi/cm3/m3-libs/m3core/src/thread/PTHREAD/ThreadPThreadC.c?rev=1.169;content-type=text%2Fplain">http://modula3.elegosoft.com/cgi-bin/cvsweb.cgi/cm3/m3-libs/m3core/src/thread/PTHREAD/ThreadPThreadC.c?rev=1.169;content-type=text%2Fplain</a><BR> <BR> <BR>Look for "M3_COMPILER_THREAD_LOCAL"<BR> <BR> <BR>Oh, only for the builtin thread local "activation".<BR> <BR> <BR>There is no mechanism within the Modula-3 language or libraries to use thread locals.<BR>To do this efficiently as you'd like, you need to extend the M3CG interface and the existing backends.<BR>Or you can do it strictly through libraries.<BR> <BR> <BR>Or you can avoid thread locals. They are almost as bad as globals.<BR>They don't make for reentrant code, only thread safe code.<BR>Consider a nested for loop using strtok, for example.<BR> <BR> <BR> > no kernel space is involved in accessing<BR> <BR> <BR>That is probably true of all implementations.<BR>Apple's is said to be fast, to that is implied.<BR>NT doesn't involve the kernel and is reasonably fast (disassemble kernel32!TlsGetValue).<BR>Allocation maybe, but not access.<BR> <BR> <BR> > Also, on Linux since 2004, uncontested lock is user-space only<BR> <BR> <BR>Linux is not alone here or necessarily better than any system.<BR>Win32 critical sections have always been user-mode only if uncontended.<BR>Modula-3 locks I believe are too.<BR> <BR> <BR>I wouldn't be surprised if every system or every current system is the same in this regard.<BR>Everyone knows that kernel calls are expensive and to be minimized.<BR> <BR> <BR> > Linux pioneered lightweight processes/threads in free *nix world, and others followed<BR> <BR> <BR>Long after probably every commercial system got it right, e.g. at least Solaris and NT, probably everything else too.<BR> <BR> <BR> - Jay<br><BR><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">From: dragisha@m3w.org<br>Date: Fri, 10 May 2013 18:39:33 +0200<br>To: mika@async.caltech.edu<br>CC: m3devel@elegosoft.com<br>Subject: Re: [M3devel] thread local storage,      but in C pieces of runtime... (jay, tony?)<br><br><div>AFAIK, Linux ABI uses dedicated register (one of segment registers) to access TLS. It's setting is part of context switch, and one is only supposed to use it read-only. No kernel space is involved in accessing, and was not since NPTL was introduced.
</div><div><br></div><div>Old and FreeBSD does ring bells :). Linux pioneered lightweight processes/threads in free *nix world, and others followed. If your test was near enough in time to 2004-5-6, then probably it was a time when FreeBSD played catch-up.</div><div><br></div><div>Also, on Linux since 2004, uncontested lock is user-space only. It probably involves a barrier of some kind, but it is under 0.5microsecond in worst case, as opposed to 20-50microsecond for kernel space operation.</div><div><br></div><div>So, it is efficient :).</div>
<br><div><div>On May 10, 2013, at 5:22 PM, <a href="mailto:mika@async.caltech.edu">mika@async.caltech.edu</a> wrote:</div><br class="ecxApple-interchange-newline"><blockquote><span class="ecxApple-style-span" style="text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; border-collapse: separate; orphans: 2; widows: 2;">This is just one data point, but I remember testing the performance of thread locals<br>on pthreads, probably on an old FreeBSD system, and the performance was horrendously<br>bad.  There was a system call involved in obtaining the pointer to the thread-local<br>area.  I was had some clever algorithms I wanted to use thread locals for (since you<br>can do all sorts of things without locks then), but I gave up on it since it was way<br>more expensive than a lock on that system...<br><br>    Mika</span></blockquote></div><br></div>                                    </div></body>
</html>