Consider system.lock or system.setSemaphore/system.releaseSemaphore.
--------------------------------------------------------------------
Key: MASHUP-991
URL: https://wso2.org/jira/browse/MASHUP-991
Project: WSO2 Mashup Server
Issue Type: Improvement
Reporter: Jonathan Marsh
Assignee: Channa Gunawardena
Fix For: Future
(12:17:30 AM) jonathan: Found a deficiency in feedCache.
(12:18:28 AM) jonathan: When calling it simultaneously (or nearly so, as
blogActivity does), the feedCache database could be overwritten with
conflicting info.
(12:18:55 AM) jonathan: Added in a simple session-based semaphore, though there
is a miniscule possibility of conflict still
(12:19:20 AM) jonathan: Between the time I see that the semaphore has cleared
and the time I set it myself, another thread could hop in and grab it first.
(12:19:34 AM) keith: hmm
(12:19:35 AM) jonathan: Which is why locking is usually a system function.
(12:20:07 AM) keith: Do u see a need fro something like system.lock in the
future?
(12:20:10 AM) jonathan: Maybe a future feature? A way to get and set locks?
(12:20:14 AM) jonathan: Yes, possibly.
(12:20:21 AM) keith: wonder how we could implement it thiugh
(12:20:36 AM) keith: cause calls can go across HO and plain JS code too
(12:21:07 AM) jonathan: If it were implemented in Java couldn't you put a Java
lock around code that tested and set?
(12:21:27 AM) keith: we could certainly do it in java
(12:21:33 AM) jonathan: Maybe instead of a traditional lock, we do a
system.semaphore.
(12:22:02 AM) keith: But here your calls that should be within a lock could
span multiple HOs and plain JS code
(12:22:15 AM) keith: which we wont be able to tackle using java
(12:22:29 AM) keith: Interesting question though
(12:22:42 AM) keith: something that might need some research into rhino too
(12:22:43 AM) jonathan: A user could do this on code that might have
concurrency problems:
(12:23:11 AM) jonathan: system.setSemaphore("foo"); // waits until "foo" is
clear, then sets it and returns.
(12:23:30 AM) jonathan: system.releaseSemaphore("foo");
(12:23:57 AM) jonathan: Here's what I'm doing now:
(12:24:16 AM) jonathan: while (session.get("semaphore") == "true") {
system.wait();
}
session.put("semaphore", "true");
try {
// stuff
session.put("semaphore", "false");
} catch (e) {
session.put("semaphore", "false");
throw (e);
}
(12:24:39 AM) jonathan: Possibility another thread could get the semaphore
between the while loop and the put.
(12:24:56 AM) keith: yeah
(12:25:15 AM) keith: the reading and writing need ti be synchronized
(12:25:20 AM) jonathan: Replace the while/put with
session.setSemaphore("writing-to-file');
(12:25:23 AM) keith: in java terms
(12:25:34 AM) jonathan: Replace the put with
session.releaseSemaphore("writing-to-file");
(12:26:05 AM) jonathan: Yes, or TEST AND SET in old machine language terms.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://wso2.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
Mashup-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/mashup-dev