![]() Topic awaiting preservation: mutex in my java script (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: Israel |
![]() 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 |
![]() The poster has demanded we remove all his contributions, less he takes legal action. |
Paranoid (IV) Inmate From: Dublin, Ireland |
![]() Mutex: |
Bipolar (III) Inmate From: Israel |
![]() 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 |
![]() 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 |
![]() Do we have In JavaScript a way I can stop/wait/sleep with no busy loop? |
Paranoid (IV) Inmate From: Dublin, Ireland |
![]() |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
![]() 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 |
Bipolar (III) Inmate From: Israel |
![]() 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 |
![]() 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 |
![]() My problem is loading XML files in a safe mode. |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
![]() 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. |