Re: Fiber Local Storage

2013-08-14 Thread Martin Nowak

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.


Re: Fiber Local Storage

2013-08-14 Thread Martin Nowak

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.


Re: Fiber Local Storage

2013-07-29 Thread Martin Nowak

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?


Re: Fiber Local Storage

2013-07-29 Thread Sean Kelly
On Jul 25, 2013, at 9:29 PM, Manu turkey...@gmail.com wrote:

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

Nope.  I'd love to have this, but it's pretty tricky once you include the need 
for dynamic library support and my time is quite limited these days.  As 
always, pull requests are very welcome :-)

Re: Fiber Local Storage

2013-07-29 Thread Luís.Marques

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!




Re: Fiber Local Storage

2013-07-29 Thread deadalnix

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.


Re: Fiber Local Storage

2013-07-26 Thread deadalnix

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).


Fiber Local Storage

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


Re: Fiber Local Storage

2013-07-25 Thread Vladimir Panteleev

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.


fiber local storage

2011-06-13 Thread SK
Not available yet, but Intel announced support for manipulating FS and GS in
user mode.  Protection for fiber local storage is one use case.
http://software.intel.com/file/36945