plemiami.blogg.se

Pseudocode writer
Pseudocode writer







pseudocode writer

So the answer to your question is yes, it could happen. The last two operations could then occur in parallel and so they would be attempting to access the same slot at the same time.

pseudocode writer

store addr(r),r1 // stores 2 to r *in memory* w = not(r,l) // since r *in memory* is still 0, load r1,addr(l) // load l (value 2) into register r1 The reader's assignment r = l is given as the above assembly operations, for which the writer performs troublesome operations in between: r=0 w=1 l=2 // (given starting conditions) The notation and specify which thread is doing what.

pseudocode writer

The first thread (the reader) would then overwrite this memory when storing from register to memory.Ĭonsider the following sequence of events. The problem in your case is that the register of one thread (say, the reader) could keep an intermediate value while another thread (writer) modifies memory. Where r1 is some register, addr(l) is the memory address of wherever l is stored, and addr(r) is the address of r. Store addr(r),r1 store register r1 to wherever r is kept So the assignment r = l would be something like the "pseudo-assembly": load r1,addr(l) load l from memory into register r1 However, threads must have their own stack and register states, otherwise they just wouldn't work.Īn assignment such as the reader's line r = l would first load a value from some memory location (wherever l is stored) into a register, then store this value to memory (wherever r is stored). Globals and heap memory are shared between threads of the same process, so this part is easy. I'm assuming that you would implement r, w, and l as variables in memory that would be visible to both threads. This introduces an intermediate state (the register) that could possibly mix things up in a multi-threaded situation such as this. there are no direct memory-to-memory operations). Most computers use a "load/store" architecture where values from memory must be moved to a register before being moved to another memory location (i.e. The difficulty is in how your pseudocode would be executed in hardware. The pseudocode is usually put in an algorithm environment.įor typesetting real code, written in a real programming language, consider the listings package described in Source Code Listings.The fundamental problem is that even variable assignment is not an atomic operation. They provide stylistic enhancements over a uniform style (i.e., all in typewriter font) so that constructs such as loops or conditionals are visually separated from other text. LaTeX has several packages for typesetting algorithms in form of " pseudocode". Collaborative Writing of LaTeX Documents.Scientific Reports (Bachelor Report, Master Thesis, Dissertation).









Pseudocode writer