How to have multiple synchronized shared types. Programming in D, page 647
Brother Bill
brotherbill at mail.com
Sun Aug 31 00:46:50 UTC 2025
The idea is that multiple shared objects use a common lock.
```
import std.stdio;
void main()
{
}
class BankAccount
{
}
void transferMoney(shared BankAccount from, shared BankAccount to)
{
synchronized (from, to) ← FAILS TO COMPILE. Doesn't like
comma.
{ // ← correct
// ...
}
}
```
This fails to compile with dmd 2.111.0
```
c:\dev\D\81 - 90\c86_4f_multiple_synchronized\source\app.d(15):
Error: using the result of a comma expression is not allowed
synchronized (from, to)
^
```
Is there another way to do this, other than manually, or is this
obsolete?
More information about the Digitalmars-d-learn
mailing list