Shared db pool

Benjamin Thaut code at benjamin-thaut.de
Mon Mar 18 14:05:51 PDT 2013


Am 18.03.2013 20:55, schrieb Alex Khmara:
> This compiles (and simplified example wit big sleeps in get and debug output seems to work correctly),
> but I am not sure about thread-safety.

Looks thread safe for me.

>
> If after that I will have no no shared-related overhead in call to Mysql methods than
> things are good - pool will not give Mysql instance to second thread until it will be relased by first thread.

The only problem you may run into, is that the destructor of PoolRef 
might gets called multiple times if you are not really carefull with 
temporary variables. Ideal would be a way to disallow copying of the 
struct and only allow moving it, last I checked this was not possible in 
D. Because when you do @disable this(this) it will also disallow moving 
the struct. Although you could try with the current version.

Kind Regards
Benjamin Thaut



More information about the Digitalmars-d-learn mailing list