Appendix A

Initial version: 2025-04-28
Last update: 2025-04-28

In this appendix you will find source codes which for some reasons are not included in previous chapters but which are required if you want to run the code presented there.

Table of contents


Implementation of `ThreadSafeList`


ThreadSafeList is a wrapper for list which:

  1. Attracts your attention to the fact that in some circumstances list should be insensitive to the operations which may be performed concurrently.
  2. Provides some extra functionality on lists specific to blockchain needs.



import random

numberOfTests = 10
target = 4
totalTries = 0

for t in range(numberOfTests):
  tries = 0
  while True:
    tries += 1
    v = random.randint(1, 100)
    if v < target:
      break
    
  totalTries += tries
  print(f"try {t}: tries={tries}, totalTries={totalTries}, average={totalTries/(t+1)}")