www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Fiber Local Storage

reply Manu <turkeyman gmail.com> writes:
--001a1133056e2b7a9d04e262987c
Content-Type: text/plain; charset=UTF-8

Is there an FLS implementation floating around?
If not, it's probably something that should be considered for std.thread.

--001a1133056e2b7a9d04e262987c
Content-Type: text/html; charset=UTF-8

<div dir="ltr">Is there an FLS implementation floating around?<div>If not,
it&#39;s probably something that should be considered for
std.thread.</div></div>

--001a1133056e2b7a9d04e262987c--
Jul 25 2013
next sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Friday, 26 July 2013 at 04:30:18 UTC, Manu wrote:
 Is there an FLS implementation floating around?
 If not, it's probably something that should be considered for 
 std.thread.

Maybe something like this: ---------------------------------- private struct FLSEntry { void** ptr; size_t start; immutable void[] initData; } private __gshared FLSEntry[] flsEntries; private __gshared size_t flsSize; void registerFLS(void** ptr, immutable void[] initData) { enum ALIGN = size_t.sizeof; auto size = (initData.length + ALIGN-1) % ALIGN; flsEntries ~= FLSEntry(ptr, flsSize, initData); flsSize += size; } // called by core.thread on fiber creation void initFLS(Fiber fiber) { fiber.fls = new void[flsSize]; void* p = fiber.fls.ptr; foreach (entry; flsEntries) with (entry) p[start..start+initData.length] = initData[]; } // called by core.thread when switching to a fiber void switchFLS(Fiber to) { void* p = to.fls.ptr; foreach (entry; flsEntries) *entry.ptr = p + entry.start; } struct FLS(T) { shared static this() { //registerFLS(&data, (&T.init)[0..1]); static immutable T init; registerFLS(cast(void**)&data, (&init)[0..1]); } static T* data; alias data this; } // *************************************** struct MyData { int i; } FLS!MyData fiberData; ---------------------------------- A linker segment would be better, but not sure how feasible that would be.
Jul 25 2013
prev sibling next sibling parent reply "deadalnix" <deadalnix gmail.com> writes:
On Friday, 26 July 2013 at 04:30:18 UTC, Manu wrote:
 Is there an FLS implementation floating around?
 If not, it's probably something that should be considered for 
 std.thread.

I'd also love to have one ! (in fact I do think it should be the default).
Jul 25 2013
parent Martin Nowak <code dawg.eu> writes:
On 07/26/2013 08:06 AM, deadalnix wrote:
 On Friday, 26 July 2013 at 04:30:18 UTC, Manu wrote:
 Is there an FLS implementation floating around?
 If not, it's probably something that should be considered for std.thread.

I'd also love to have one ! (in fact I do think it should be the default).

What do you mean by that, FLS instead of TLS and everything runs as Fiber?
Jul 29 2013
prev sibling next sibling parent =?UTF-8?B?Ikx1w61z?= Marques" <luismarques gmail.com> writes:
On Friday, 26 July 2013 at 04:30:18 UTC, Manu wrote:
 Is there an FLS implementation floating around?
 If not, it's probably something that should be considered for 
 std.thread.

Nice to see this asked. For a simulation library I was developing I was thinking that fiber support had to be done by asking the library user to swap a struct every time a fiber context-switched. If that could be automated then that would be great!
Jul 29 2013
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Monday, 29 July 2013 at 15:25:49 UTC, Martin Nowak wrote:
 On 07/26/2013 08:06 AM, deadalnix wrote:
 On Friday, 26 July 2013 at 04:30:18 UTC, Manu wrote:
 Is there an FLS implementation floating around?
 If not, it's probably something that should be considered for 
 std.thread.

I'd also love to have one ! (in fact I do think it should be the default).

What do you mean by that, FLS instead of TLS and everything runs as Fiber?

Yes, with a scheduler int the runtime.
Jul 29 2013
prev sibling next sibling parent "Martin Nowak" <code dawg.eu> writes:
On Tuesday, 30 July 2013 at 01:45:45 UTC, deadalnix wrote:
 On Monday, 29 July 2013 at 15:25:49 UTC, Martin Nowak wrote:
 What do you mean by that, FLS instead of TLS and everything 
 runs as Fiber?

Yes, with a scheduler int the runtime.

I don't think FLS can be as fast as TLS because the latter benefits from many optimizations due to linker and OS support.
Aug 14 2013
prev sibling parent "Martin Nowak" <code dawg.eu> writes:
On Friday, 26 July 2013 at 04:30:18 UTC, Manu wrote:
 Is there an FLS implementation floating around?
 If not, it's probably something that should be considered for 
 std.thread.

- There is WorkerLocalStorage in std.parallelism Tasks. - Apparently you can easily capture variables in the context of the delegate. - If you use thread affinity when executing Fibers you can access TLS.
Aug 14 2013