digitalmars.D.learn - Problem about multi-thread programming
- Tongzhou Li (6/6) May 05 2012 Hello everyone! I'm learning D and trying to write some sample
- Kagamin (1/1) May 05 2012 What's in console?
- Tongzhou Li (8/9) May 05 2012 object.Error: Access Violation
- Chris Cain (8/17) May 05 2012 By default, everything is TLS (thread local) ... so, cv[0] will
- Tongzhou Li (4/24) May 05 2012 Thanks. Now it works fine with gdc, but still prints nothing with
- Chris Cain (6/9) May 06 2012 I'm not exactly sure what's going on for it not to work for you,
- Tongzhou Li (2/11) May 06 2012 I used stdout.flush() then it works. Thanks.
- David Nadlinger (5/6) May 05 2012 Besides the other things mentioned, you also need to lock the
- Tongzhou Li (2/8) May 05 2012 Why? There's no data races...
- David Nadlinger (4/5) May 06 2012 It's part of the protocol/contract/whatever you want to call it
Hello everyone! I'm learning D and trying to write some sample code in D. I wrote: http://codepad.org/K4xQOREZ It compiles well with dmd 2.0.59, but I got an error when running: object.Error: Access Violation Any one help? Thanks.
May 05 2012
On Saturday, 5 May 2012 at 09:16:04 UTC, Kagamin wrote:What's in console?object.Error: Access Violation ---------------- ---------------- Expected output: 12341234123.... PS: Line 13 should be: write(Idx);
May 05 2012
On Saturday, 5 May 2012 at 09:28:34 UTC, Tongzhou Li wrote:On Saturday, 5 May 2012 at 09:16:04 UTC, Kagamin wrote:By default, everything is TLS (thread local) ... so, cv[0] will be null in main even though another thread set it to something else. Adding __gshared in front of "Condition[4] cv;" on line 7 will make it not crash with the Access Violation. However, I highly recommend you read the concurrency chapter in the DPL book: http://www.informit.com/articles/article.aspx?p=1609144What's in console?object.Error: Access Violation ---------------- ---------------- Expected output: 12341234123.... PS: Line 13 should be: write(Idx);
May 05 2012
On Saturday, 5 May 2012 at 17:03:00 UTC, Chris Cain wrote:On Saturday, 5 May 2012 at 09:28:34 UTC, Tongzhou Li wrote:Thanks. Now it works fine with gdc, but still prints nothing with dmd. It seems that "cv[0].notify()" on line 29 affects nothing at all when using dmd2 :(On Saturday, 5 May 2012 at 09:16:04 UTC, Kagamin wrote:By default, everything is TLS (thread local) ... so, cv[0] will be null in main even though another thread set it to something else. Adding __gshared in front of "Condition[4] cv;" on line 7 will make it not crash with the Access Violation. However, I highly recommend you read the concurrency chapter in the DPL book: http://www.informit.com/articles/article.aspx?p=1609144What's in console?object.Error: Access Violation ---------------- ---------------- Expected output: 12341234123.... PS: Line 13 should be: write(Idx);
May 05 2012
On Sunday, 6 May 2012 at 04:52:48 UTC, Tongzhou Li wrote:Thanks. Now it works fine with gdc, but still prints nothing with dmd. It seems that "cv[0].notify()" on line 29 affects nothing at all when using dmd2 :(I'm not exactly sure what's going on for it not to work for you, but here's the code I have (I used stdout.flush() because in some command prompts it won't display until it reaches a new line '\n' character otherwise). Maybe this will work better. https://gist.github.com/5a9b7f611f33ee143880
May 06 2012
On Sunday, 6 May 2012 at 10:39:04 UTC, Chris Cain wrote:On Sunday, 6 May 2012 at 04:52:48 UTC, Tongzhou Li wrote:I used stdout.flush() then it works. Thanks.Thanks. Now it works fine with gdc, but still prints nothing with dmd. It seems that "cv[0].notify()" on line 29 affects nothing at all when using dmd2 :(I'm not exactly sure what's going on for it not to work for you, but here's the code I have (I used stdout.flush() because in some command prompts it won't display until it reaches a new line '\n' character otherwise). Maybe this will work better. https://gist.github.com/5a9b7f611f33ee143880
May 06 2012
On Saturday, 5 May 2012 at 08:45:21 UTC, Tongzhou Li wrote:I wrote: http://codepad.org/K4xQOREZBesides the other things mentioned, you also need to lock the monitor associated with a condition before notifying/waiting (cf. a recent discussion on the druntime list). David
May 05 2012
On Saturday, 5 May 2012 at 18:46:32 UTC, David Nadlinger wrote:On Saturday, 5 May 2012 at 08:45:21 UTC, Tongzhou Li wrote:Why? There's no data races...I wrote: http://codepad.org/K4xQOREZBesides the other things mentioned, you also need to lock the monitor associated with a condition before notifying/waiting (cf. a recent discussion on the druntime list). David
May 05 2012
On Sunday, 6 May 2012 at 04:54:44 UTC, Tongzhou Li wrote:Why? There's no data races...It's part of the protocol/contract/whatever you want to call it of condition variables as implemented in druntime. David
May 06 2012