Comments (5)
Yes, generally you are on your own when it comes to locking of structures.
However, I agree you should be able to access (but not create or delete)
items from a hash without a lock. I think the problem here is that the ++
is generating a "set" command and even though the item exists and therefor
no insert will happen, it still iterates over the tree (and mutates it by
the look of the code - I did not write it). I think the best solution
would be for an optimised no-mutate path for the case of when the value is
already in the tree. This should save some allocs too.
On Mon, Feb 17, 2014 at 10:44 PM, maxless [email protected] wrote:
The following example while technically does not have any racing
conditions, produces segfault in HXCPP on Linux 64-bit. It works fine in
Neko environment.#if neko
import neko.vm.Thread;
#elseif cpp
import cpp.vm.Thread;
#endclass Test
{
var anon: { v1: Int, v2: Int };public function new()
{
anon = { v1: 0, v2: 0 };
var t1 = Thread.create(t1run);
var t2 = Thread.create(t2run);
}function t1run()
{
while (true)
anon.v1++;
}function t2run()
{
while (true)
anon.v2++;
}public static function main()
{
var t = new Test();
while (true)
Sys.sleep(1);
}
}Running it through GDB shows that the segfault is in one of the lines in
RBTree implementation (I'm using the latest git version currently, switched
over from using 3.0.2 because of another bug):0x0000000000477aa6 in RBTree<String, Dynamic>::Insert (this=0x7ffff7ee5a44, inKey=..., inValue=...) at /home/maxless/svn/hxcpp/src/hx/RedBlack.h:159
159 root->red = 0;0x0000000000477a35 in RBTree<String, Dynamic>::Insert (this=0x7ffff7ee5a44, inKey=..., inValue=...) at /home/maxless/svn/hxcpp/src/hx/RedBlack.h:155
155 root = tmp_head->link[1];Changing anon object into a full new class is a workaround that I've found.
Now I understand what happens here - each anon object only has a one
RBTree of fields and the implementation is not thread-safe. That code is
probably considered a bad practice but it should work nonetheless. Or at
least it should be documented somewhere.Reply to this email directly or view it on GitHubhttps://github.com//issues/23
.
from hxcpp.
I have put a fix in RedBlack.h - should fix the problem. Hopefully it is a
net performance gain.
On Tue, Feb 18, 2014 at 10:21 AM, Hugh Sanderson [email protected] wrote:
Yes, generally you are on your own when it comes to locking of structures.
However, I agree you should be able to access (but not create or delete)
items from a hash without a lock. I think the problem here is that the ++
is generating a "set" command and even though the item exists and therefor
no insert will happen, it still iterates over the tree (and mutates it by
the look of the code - I did not write it). I think the best solution
would be for an optimised no-mutate path for the case of when the value is
already in the tree. This should save some allocs too.On Mon, Feb 17, 2014 at 10:44 PM, maxless [email protected]:
The following example while technically does not have any racing
conditions, produces segfault in HXCPP on Linux 64-bit. It works fine in
Neko environment.#if neko
import neko.vm.Thread;
#elseif cpp
import cpp.vm.Thread;
#endclass Test
{
var anon: { v1: Int, v2: Int };public function new()
{
anon = { v1: 0, v2: 0 };
var t1 = Thread.create(t1run);
var t2 = Thread.create(t2run);
}function t1run()
{
while (true)
anon.v1++;
}function t2run()
{
while (true)
anon.v2++;
}public static function main()
{
var t = new Test();
while (true)
Sys.sleep(1);
}
}Running it through GDB shows that the segfault is in one of the lines in
RBTree implementation (I'm using the latest git version currently, switched
over from using 3.0.2 because of another bug):0x0000000000477aa6 in RBTree<String, Dynamic>::Insert (this=0x7ffff7ee5a44, inKey=..., inValue=...) at /home/maxless/svn/hxcpp/src/hx/RedBlack.h:159
159 root->red = 0;0x0000000000477a35 in RBTree<String, Dynamic>::Insert (this=0x7ffff7ee5a44, inKey=..., inValue=...) at /home/maxless/svn/hxcpp/src/hx/RedBlack.h:155
155 root = tmp_head->link[1];Changing anon object into a full new class is a workaround that I've
found.Now I understand what happens here - each anon object only has a one
RBTree of fields and the implementation is not thread-safe. That code is
probably considered a bad practice but it should work nonetheless. Or at
least it should be documented somewhere.Reply to this email directly or view it on GitHubhttps://github.com//issues/23
.
from hxcpp.
I think the best solution would be for an optimised no-mutate path for the case of when the value is already in the tree. This should save some allocs too.
Yes, that sounds perfect.
I have put a fix in RedBlack.h - should fix the problem.
I've tested the changes for some time, it looks stable now both in the test and my application.
Hopefully it is a net performance gain.
I happen to have a rough test available - it creates an anon object, then does some get/sets in a loop, measuring full runtime. With the fixed RedBlack.h anon object set field sped up by ~30% and Reflect.setField() by ~40%. But don't quote me on that, that's just a simplistic measurement for my purposes.
from hxcpp.
BTW, I don't know if it's a known fact or some mistake, but accessing fields of anonymous objects (a = obj.Integer3) is almost twice slower in hxcpp than in neko.
from hxcpp.
Should be good now. Neko converts the string indexes to int hash keys at compile time, and then uses int lookups, so this could be the reason.
from hxcpp.
Related Issues (20)
- Arm64 for iOS Simulator
- Next `haxelib` release when?
- OnExit? Is there a way to call code when executable is done and shutting down?
- Build linux target from Macos. HOT 2
- f16/half worth supporting?
- wasm is not working with hxcpp HOT 2
- NME Android build error
- String::create(wchar_t* ...) is broken on non Windows systems
- Adding support for vs 2022
- HXCPP_API_LEVEL 300 Cleanup HOT 1
- GC Pinning HOT 4
- How to properly shutdown a hxcpp DLL?
- Casts inserted and I don't know why HOT 2
- FreeBSD, Could not find include file "toolchain/null-toolchain.xml" HOT 1
- Strange CPP error HOT 2
- Pointer_obj::ofArray changes length of empty array from 0 to 1
- Allow using system sqlite?
- Linking issue on HXCPP_MINGW under MSYS2 HOT 2
- Cannot have an array of pointers HOT 2
- hxcpp does not quote -I paths with spaces
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hxcpp.