digitalmars.D - Fiber Local Storage
- Manu (2/2) Jul 25 2013 Is there an FLS implementation floating around?
- Vladimir Panteleev (54/57) Jul 25 2013 Maybe something like this:
- deadalnix (3/6) Jul 25 2013 I'd also love to have one ! (in fact I do think it should be the
- Martin Nowak (2/6) Jul 29 2013 What do you mean by that, FLS instead of TLS and everything runs as Fibe...
- deadalnix (2/12) Jul 29 2013 Yes, with a scheduler int the runtime.
- Martin Nowak (3/7) Aug 14 2013 I don't think FLS can be as fast as TLS because the latter
- =?UTF-8?B?Ikx1w61z?= Marques" (6/9) Jul 29 2013 Nice to see this asked. For a simulation library I was developing
- Martin Nowak (6/9) Aug 14 2013 - There is WorkerLocalStorage in std.parallelism Tasks.
Is there an FLS implementation floating around? If not, it's probably something that should be considered for std.thread.
Jul 25 2013
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
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
On 07/26/2013 08:06 AM, deadalnix wrote:On Friday, 26 July 2013 at 04:30:18 UTC, Manu wrote:What do you mean by that, FLS instead of TLS and everything runs as Fiber?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 29 2013
On Monday, 29 July 2013 at 15:25:49 UTC, Martin Nowak wrote:On 07/26/2013 08:06 AM, deadalnix wrote:Yes, with a scheduler int the runtime.On Friday, 26 July 2013 at 04:30:18 UTC, Manu wrote:What do you mean by that, FLS instead of TLS and everything runs as Fiber?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 29 2013
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:I don't think FLS can be as fast as TLS because the latter benefits from many optimizations due to linker and OS support.What do you mean by that, FLS instead of TLS and everything runs as Fiber?Yes, with a scheduler int the runtime.
Aug 14 2013
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
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