sharing_20a_20structure_20between_20processes
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sharing_20a_20structure_20between_20processes [2018/03/31 13:19] – external edit 127.0.0.1 | sharing_20a_20structure_20between_20processes [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
//by Richard Russell, October 2014//\\ \\ Most modern PCs have multiple CPU cores, often four or more. If you are creating a computationally-intensive application you may wish to take advantage of this feature, but that is not so easy to do in BBC BASIC. One approach is to code some of the functionality in assembly language (using the built-in assembler) which can be arranged to run in a separate thread, and therefore potentially on a different core. However this requires specialised skills which not all BASIC programmers can be expected to acquire; debugging assembler code can also be difficult.\\ \\ If you are coding purely in BASIC there is really only one way to take advantage of multiple CPU cores, and that is to run multiple executables, | //by Richard Russell, October 2014//\\ \\ Most modern PCs have multiple CPU cores, often four or more. If you are creating a computationally-intensive application you may wish to take advantage of this feature, but that is not so easy to do in BBC BASIC. One approach is to code some of the functionality in assembly language (using the built-in assembler) which can be arranged to run in a separate thread, and therefore potentially on a different core. However this requires specialised skills which not all BASIC programmers can be expected to acquire; debugging assembler code can also be difficult.\\ \\ If you are coding purely in BASIC there is really only one way to take advantage of multiple CPU cores, and that is to run multiple executables, | ||
+ | <code bb4w> | ||
FILE_MAP_WRITE = 2 | FILE_MAP_WRITE = 2 | ||
PAGE_READWRITE = 4 | PAGE_READWRITE = 4 | ||
Line 12: | Line 13: | ||
IF pShared% = 0 ERROR 0, " | IF pShared% = 0 ERROR 0, " | ||
!(^Shared{}+4) = pShared% | !(^Shared{}+4) = pShared% | ||
+ | </ | ||
The string shown as **" | The string shown as **" | ||
+ | <code bb4w> | ||
Shared.member& | Shared.member& | ||
PRINT Shared.member& | PRINT Shared.member& | ||
+ | </ | ||
In your program' | In your program' | ||
+ | <code bb4w> | ||
pShared% += 0 : IF pShared% SYS " | pShared% += 0 : IF pShared% SYS " | ||
hMap% += 0 : IF hMap% SYS " | hMap% += 0 : IF hMap% SYS " | ||
+ | </ | ||
It is extremely important that two or more processes don't attempt to write to the same structure member at the same time. The safest way to guarantee that is for each structure member to be writable only by **one** of your processes, and read-only to all the others.\\ \\ Also, be aware of the possibility that the data read by one process may be invalid because it is concurrently being written by another process (if it's an aligned 32-bit integer you can probably be assured of an ' | It is extremely important that two or more processes don't attempt to write to the same structure member at the same time. The safest way to guarantee that is for each structure member to be writable only by **one** of your processes, and read-only to all the others.\\ \\ Also, be aware of the possibility that the data read by one process may be invalid because it is concurrently being written by another process (if it's an aligned 32-bit integer you can probably be assured of an ' |
sharing_20a_20structure_20between_20processes.1522502381.txt.gz · Last modified: 2024/01/05 00:16 (external edit)