RejectedSoftware Forums

Sign up

new DMD deprecates read-modify-write operations on shared variables

new DMD deprecates read-modify-write operations on shared variables and issues warning in core.d. the following patch fixes the warning. i'm not sure if it is really necessary to do atomic operation there, but it will not break anything anyway.

diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d
index 08ecdd7..13f19a0 100644
--- a/source/vibe/core/core.d
+++ b/source/vibe/core/core.d
@@ -197,7 +197,7 @@ Task runTask(ARGS…)(void delegate(ARGS) task, ARGS args)
 	f.m_taskDelegate = Variant(task);
 	static if (ARGS.length) f.m_taskArgs = VariantN!MaxTaskParameterSize(tuple(args));
 	f.m_taskFunc = &callDelegate;
-	f.m_taskCounter++;
+	core.atomic.atomicOp!"+="(f.m_taskCounter, 1);
 	auto handle = f.task();
 	debug Task self = Task.getThis();
 	debug if (s_taskEventCallback) {

Re: new DMD deprecates read-modify-write operations on shared variables

On Tue, 03 Jun 2014 09:28:45 GMT, fcl wrote:

new DMD deprecates read-modify-write operations on shared variables and issues warning in core.d. the following patch fixes the warning. i'm not sure if it is really necessary to do atomic operation there, but it will not break anything anyway.

diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d
index 08ecdd7..13f19a0 100644
--- a/source/vibe/core/core.d
+++ b/source/vibe/core/core.d
@@ -197,7 +197,7 @@ Task runTask(ARGS…)(void delegate(ARGS) task, ARGS args)
 	f.m_taskDelegate = Variant(task);
 	static if (ARGS.length) f.m_taskArgs = VariantN!MaxTaskParameterSize(tuple(args));
 	f.m_taskFunc = &callDelegate;
-	f.m_taskCounter++;
+	core.atomic.atomicOp!"+="(f.m_taskCounter, 1);
 	auto handle = f.task();
 	debug Task self = Task.getThis();
 	debug if (s_taskEventCallback) {

Thanks, committed as 72143bf. The atomic operation isn't really needed here, because only a single thread ever modifies the counter, but I'll leave that to a later optimization, if necessary.