|
|
Subject: Re: NSOperation, Sqlite, library routine called out of sequence - msg#02187
List: cocoa-dev
ÐÐÐÐÑÐÐ ÐÐÐÑÑÐÐ wrote:
The DatabaseManager is synchronized. If any class is to communicate
with the db, it does that through the DatabaseManager. The latter
just provides proxy methods. I think, that should result in classes
getting the instance of the DatabaseManager only when it is no
longer (or not yet) used by other classes.
But that does nothing to prevent multiple threads from performing
additional concurrent actions on the database. It's not enough to
just control access to the shared singleton, if the actions performed
by the singleton aren't also thread-safe. All the queries, updates,
etc. need thread-safety, too.
-- GG
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us
This email sent to maillists@xxxxxxxxx
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
Re: NSOperation, Sqlite, library routine called out of sequence
The DatabaseManager is synchronized. If any class is to communicate
with the db, it does that through the DatabaseManager. The latter just
provides proxy methods. I think, that should result in classes getting
the instance of the DatabaseManager only when it is no longer (or not
yet) used by other classes.
+ (DatabaseManager*)sharedManager {
@synchronized(self) {
if (sharedDatabaseManager == nil) {
[[self alloc] init]; // assignment not done here
}
}
return sharedDatabaseManager;
}
+ (id)allocWithZone:(NSZone *)zone {
@synchronized(self) {
if (sharedDatabaseManager == nil) {
sharedDatabaseManager = [super allocWithZone:zone];
[sharedDatabaseManager initDb];
return sharedDatabaseManager;
}
}
return nil;
}
On Apr 29, 2009, at 10:52 PM, Greg Guerin wrote:
ÐÐÐÐÑÐÐ ÐÐÐÑÑÐÐ wrote:
In short, i get an error calling the same synchronized singleton
DatabaseManager from different threads.
Are you sure your database accesses are synchronized (i.e. thread-
safe)? I see nothing in the posted code that uses @synchronized or
any other locking mechanism.
-- GG
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/ok5.admin%40gmail.com
This email sent to ok5.admin@xxxxxxxxx
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us
This email sent to maillists@xxxxxxxxx
Next Message by Date:
click to view message preview
Re: NSOperation, Sqlite, library routine called out of sequence
Hm...
That really works! Thanks a lot.
Putting the bodies of those methods in @synchronized(self) blocks helped
Thanks a lot again.
On Apr 29, 2009, at 11:33 PM, Greg Guerin wrote:
ÐÐÐÐÑÐÐ ÐÐÐÑÑÐÐ wrote:
The DatabaseManager is synchronized. If any class is to communicate
with the db, it does that through the DatabaseManager. The latter
just provides proxy methods. I think, that should result in classes
getting the instance of the DatabaseManager only when it is no
longer (or not yet) used by other classes.
But that does nothing to prevent multiple threads from performing
additional concurrent actions on the database. It's not enough to
just control access to the shared singleton, if the actions
performed by the singleton aren't also thread-safe. All the
queries, updates, etc. need thread-safety, too.
-- GG
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/ok5.admin%40gmail.com
This email sent to ok5.admin@xxxxxxxxx
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us
This email sent to maillists@xxxxxxxxx
Previous Message by Thread:
click to view message preview
Re: NSOperation, Sqlite, library routine called out of sequence
The DatabaseManager is synchronized. If any class is to communicate
with the db, it does that through the DatabaseManager. The latter just
provides proxy methods. I think, that should result in classes getting
the instance of the DatabaseManager only when it is no longer (or not
yet) used by other classes.
+ (DatabaseManager*)sharedManager {
@synchronized(self) {
if (sharedDatabaseManager == nil) {
[[self alloc] init]; // assignment not done here
}
}
return sharedDatabaseManager;
}
+ (id)allocWithZone:(NSZone *)zone {
@synchronized(self) {
if (sharedDatabaseManager == nil) {
sharedDatabaseManager = [super allocWithZone:zone];
[sharedDatabaseManager initDb];
return sharedDatabaseManager;
}
}
return nil;
}
On Apr 29, 2009, at 10:52 PM, Greg Guerin wrote:
ÐÐÐÐÑÐÐ ÐÐÐÑÑÐÐ wrote:
In short, i get an error calling the same synchronized singleton
DatabaseManager from different threads.
Are you sure your database accesses are synchronized (i.e. thread-
safe)? I see nothing in the posted code that uses @synchronized or
any other locking mechanism.
-- GG
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/ok5.admin%40gmail.com
This email sent to ok5.admin@xxxxxxxxx
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us
This email sent to maillists@xxxxxxxxx
Next Message by Thread:
click to view message preview
Re: NSOperation, Sqlite, library routine called out of sequence
Hm...
That really works! Thanks a lot.
Putting the bodies of those methods in @synchronized(self) blocks helped
Thanks a lot again.
On Apr 29, 2009, at 11:33 PM, Greg Guerin wrote:
ÐÐÐÐÑÐÐ ÐÐÐÑÑÐÐ wrote:
The DatabaseManager is synchronized. If any class is to communicate
with the db, it does that through the DatabaseManager. The latter
just provides proxy methods. I think, that should result in classes
getting the instance of the DatabaseManager only when it is no
longer (or not yet) used by other classes.
But that does nothing to prevent multiple threads from performing
additional concurrent actions on the database. It's not enough to
just control access to the shared singleton, if the actions
performed by the singleton aren't also thread-safe. All the
queries, updates, etc. need thread-safety, too.
-- GG
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/ok5.admin%40gmail.com
This email sent to ok5.admin@xxxxxxxxx
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us
This email sent to maillists@xxxxxxxxx
|
|