digitalmars.D.learn - Strange Thread Causing Duplicating `writeln`
- Jonathan (42/42) Apr 09 2018 I am totally lost on why this is happening.
- Cym13 (3/45) Apr 09 2018 I don't know, but I can't reproduce either with dmd or ldc. What
- Jonathan (2/4) Apr 09 2018 dmd -run file.d
- Jonathan (2/6) Apr 09 2018 I am on Window 10 btw.
- Jonathan (2/9) Apr 09 2018 Hum, LDC does not do it for me?
- Steven Schveighoffer (7/15) Apr 10 2018 It's a windows 32-bit issue (specifically, DMC's FILE *, upon which
- Jonathan (3/18) Apr 11 2018 Hum, thank you.
I am totally lost on why this is happening.
I stripped the code down to what appears to be the most minimal
code that still causes the problem.
---
import core.sync.mutex;
import core.thread;
import std.stdio;
__gshared Mutex m;//__gshared just for testing (;
void thread1() {
foreach (i;0..8) {
synchronized(m) {
writeln("a1-",i);
}
writeln("a2-",i);
}
}
void thread2() {
foreach (i;0..8) {
synchronized(m) {
writeln("b1-",i);
}
writeln("b2-",i);
}
}
void main() {
m = new Mutex();
new Thread(&thread1).start;
new Thread(&thread2).start;
}
---
The beginning of the output for this code is:
a1-0
a2-0
a2-0
b1-0
b2-0
b2-0
a1-1
a2-1
a2-1
Why is the "a2" and "b2" writeln being repeated?!
Apr 09 2018
On Monday, 9 April 2018 at 22:28:45 UTC, Jonathan wrote:
I am totally lost on why this is happening.
I stripped the code down to what appears to be the most minimal
code that still causes the problem.
---
import core.sync.mutex;
import core.thread;
import std.stdio;
__gshared Mutex m;//__gshared just for testing (;
void thread1() {
foreach (i;0..8) {
synchronized(m) {
writeln("a1-",i);
}
writeln("a2-",i);
}
}
void thread2() {
foreach (i;0..8) {
synchronized(m) {
writeln("b1-",i);
}
writeln("b2-",i);
}
}
void main() {
m = new Mutex();
new Thread(&thread1).start;
new Thread(&thread2).start;
}
---
The beginning of the output for this code is:
a1-0
a2-0
a2-0
b1-0
b2-0
b2-0
a1-1
a2-1
a2-1
Why is the "a2" and "b2" writeln being repeated?!
I don't know, but I can't reproduce either with dmd or ldc. What
was your compilation line?
Apr 09 2018
On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:I don't know, but I can't reproduce either with dmd or ldc. What was your compilation line?dmd -run file.d
Apr 09 2018
On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote:On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:I am on Window 10 btw.I don't know, but I can't reproduce either with dmd or ldc. What was your compilation line?dmd -run file.d
Apr 09 2018
On Monday, 9 April 2018 at 22:56:33 UTC, Jonathan wrote:On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote:Hum, LDC does not do it for me?On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:I am on Window 10 btw.I don't know, but I can't reproduce either with dmd or ldc. What was your compilation line?dmd -run file.d
Apr 09 2018
On 4/9/18 6:56 PM, Jonathan wrote:On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote:It's a windows 32-bit issue (specifically, DMC's FILE *, upon which std.stdio.File is based, is thread unsafe). Try -m64. https://issues.dlang.org/show_bug.cgi?id=18483 http://bugzilla.digitalmars.com/issues/show_bug.cgi?id=327 -SteveOn Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:I am on Window 10 btw.I don't know, but I can't reproduce either with dmd or ldc. What was your compilation line?dmd -run file.d
Apr 10 2018
On Tuesday, 10 April 2018 at 23:59:08 UTC, Steven Schveighoffer wrote:On 4/9/18 6:56 PM, Jonathan wrote:Hum, thank you.On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote:It's a windows 32-bit issue (specifically, DMC's FILE *, upon which std.stdio.File is based, is thread unsafe). Try -m64. https://issues.dlang.org/show_bug.cgi?id=18483 http://bugzilla.digitalmars.com/issues/show_bug.cgi?id=327 -SteveOn Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:I am on Window 10 btw.I don't know, but I can't reproduce either with dmd or ldc. What was your compilation line?dmd -run file.d
Apr 11 2018









Jonathan <JonathanILevi gmail.com> 