Re: [fpc-pascal] Threadvar member field
On 17.03.2017 23:51, African Wild Dog wrote: I will have to redesign my classes =(. Maybe you just can add a field denoting the thread (by n integer) and set this when creating an instance, and later just read it for the appropriate purpose... -Michael ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Threadvar member field
On 17.03.2017 17:13, Karoly Balogh (Charlie/SGR) wrote: This is actually entirely platform specific. The underlying implementation of threadvars is very different for each platform, and highly depends both on the CPU arch and the OS. That might be true. Last time I checked (several years ago), the fpc implementations did OS calls when accessing thread vars with X86 architecture for Windows. This is not necessary. All C compilers I checked don't do this, but use a dedicated segment register, even though this (at that time) was not documented by Microsoft. Linux C compilers use a dedicated Segment register, as well, here its a regular documented feature of the OS. (I don't remember what fpc did for Linux at that time.) Hopefully 64 bit platforms are better (and decently documented) on that behalf. No idea about ARM etc. -Michael ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Threadvar member field
2017-03-17 5:50 GMT-03:00 Michael Schnell: > On 16.03.2017 19:38, African Wild Dog wrote: > >> I have a class where its instances are shared between multiple threads. >> How can I declare one variable per instance per thread? >> > Does this really make sense ? > > Accessing threadvars (in fpc) costs a lot more CPU cycles (i.e. involves > an OS call) than accessing normal variables. > > Supposedly the way to go is to do per-thread instances of a class, that > might reference the other classes you want to instantiate. > > I have huge collection of objects (abot 1 million) in memory so if i go with per-thread instance it will consume the entire memory ram. I will have to redesign my classes =(. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Threadvar member field
Hi, On Fri, 17 Mar 2017, Michael Schnell wrote: > Accessing threadvars (in fpc) costs a lot more CPU cycles (i.e. involves > an OS call) than accessing normal variables. This is actually entirely platform specific. The underlying implementation of threadvars is very different for each platform, and highly depends both on the CPU arch and the OS. On some platforms, threadvars are barely slower than normal ones, other platforms have the large penalty you're talking about. I agree though that it's still wise to count on the worst case scenario though. Charlie ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Threadvar member field
On 16.03.2017 19:38, African Wild Dog wrote: I have a class where its instances are shared between multiple threads. How can I declare one variable per instance per thread? Does this really make sense ? Accessing threadvars (in fpc) costs a lot more CPU cycles (i.e. involves an OS call) than accessing normal variables. Supposedly the way to go is to do per-thread instances of a class, that might reference the other classes you want to instantiate. -Michael ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Threadvar member field
On Thu, 16 Mar 2017, African Wild Dog wrote: I have a class where its instances are shared between multiple threads. How can I declare one variable per instance per thread? The code below does not compile (fpc 3.0.0): TMyClass = class public threadvar MyValue: Integer; end; This is not foreseen as a language construct, you must do this yourself. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal