Topic awaiting preservation: mutex in my java script |
|
---|---|
Author | Thread |
Bipolar (III) Inmate From: Israel |
posted 11-10-2003 13:58
Do you have any idea, how can I implement a mutex in my java script code? |
Paranoid (IV) Mad Scientist From: Somewhere over the rainbow |
posted 11-10-2003 14:01
The poster has demanded we remove all his contributions, less he takes legal action. |
Paranoid (IV) Inmate From: Dublin, Ireland |
posted 11-10-2003 14:30
Mutex: |
Bipolar (III) Inmate From: Israel |
posted 11-10-2003 14:45
My page loads data from the server and according to the user events and I want to avoid 2 parallel calls. |
Paranoid (IV) Inmate From: France |
posted 11-10-2003 14:53
The only areas I've heard of mutex was for kernel programming. quote: Ok, so you should be able to do the mutex by hand. Simply put a sort of flag ( e.g. a file, a record in a database ... ) that tells that a process already works on the datas. The process must wait until the flag is off ( e.g. the file no longer exist, the record is set to false ... ) to start. Once the process is over, simply unset the flag to allow the concurent process to start. |
Bipolar (III) Inmate From: Israel |
posted 11-10-2003 17:23
Do we have In JavaScript a way I can stop/wait/sleep with no busy loop? |
Paranoid (IV) Inmate From: Dublin, Ireland |
posted 11-12-2003 11:37 |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 11-12-2003 18:06
A language which does not have threads (such as JavaScript) does not need mutexes. If you want to avoid doing certain things while you're waiting for something else to complete, you can simply keep a flag variable which says that you're waiting, and if it's true, you don't do anything else (if (waiting) return . Then, when you're done doing whatever you're waiting for, you go back and do the things that you wanted to do while you were waiting. |
Bipolar (III) Inmate From: Israel |
posted 11-12-2003 18:20
It looks like the load of outside XML open a new connection to the server and works asynchronic. |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 11-12-2003 21:51
Despite the XML loading being asynchronic, there is only one "thread" (your javascript program) which needs to access the "critical section" (the launching and recieving of an HTTP request). Two JavaScript functions cannot be run simultaneously, so I think you're overcomplicating things. |
Bipolar (III) Inmate From: Israel |
posted 11-13-2003 07:51
My problem is loading XML files in a safe mode. |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 11-13-2003 08:02
I believe you can be guaranteed that two javascript functions in the same window will never be executed at the same time. If you have multiple windows, simply communicate between them and make sure only one of them actually does the stuff that can't be done more than once at a time. |