[sword-devel] SWORD multi-session/thread support

Troy A. Griffitts scribe at crosswire.org
Fri Jul 30 01:47:55 MST 2010

Yes Manfred,  SWModule can be seen as an iterator over a set of data. 
If you wish to have two different states of iteration then you need two
instances.  There are methods for this and two different predominant
ways to handle it in your app.  Example scenario below-- display and search:

SWMgr library;
SWModule *bookForDisplay = library.getModule("KJV");
// display
SWModule *bookForSearch = bookForDisplay->clone();
// do my search
delete bookForSearch;


SWMgr libraryForDisplay;
SWMgr libraryForSearch;
SWModule *bookForDisplay = libraryForDisplay.getModule("KJV");
SWModule *bookForSearch = libraryForSearch.getModule("KJV");
// do my search

Hope this gives some ideas,


On 07/30/2010 12:54 AM, Manfred Bergmann wrote:
> Hi.
> Vadim's question in sword-support made me think a little.
> SWMgr being or used as a singleton is fine. Somewhere there is always as synchronisation point.
> But if I'm not mistaken the modules you get via the list are all the same instances. I mean, suppose there are two threads, each retrieve the same module from SWMgr.
> They do both retrieve the same module instance, don't they?
> Now if both want to iterate over the module this will cause problems. In MacSword/PocketSword we use semaphores to lock the modules so that no two threads can position and pull text at the same time. This however is very bad for multi-threaded environments like a web application is.
> Is there a way to retrieve different instances of modules from SWMgr? Or can there be multiple instances of SWMgr?
> Manfred
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page

More information about the sword-devel mailing list