原子列表API¶
模塊shared_atomic
列表提供原子操作,列表必須不超過8字節
構造函數提供原子操作,列表必須不超過8字節
- 參數
initial – 列表的初始值,如果初始值長於8字節,請指定截短的目標字節數,否則會失敗
mode – 列表的共享模式,』singleprocessing’或者’s’是單進程模式,』multiprocessing’或者’m’是多進程模式在windows平臺上只支持單進程模式,設成’multiprocessing’或者’m’會被忽略。
encoding – 字符集,默認值’utf-8』
在單進程與多進程模式之間切換,原來的內容會被複制到新的共享數組中,因為windows平臺上只有單進程模式,這個函數在windows上並不存在,其它進程或者線程無法感知這種改變
- 參數
newmode – 需要切換的模式,』m』 或者 『multiprocessing』 是多進程模式, 『s』 or 『singleprocessing’單進程模式. 默認值是多進程模式
- 回傳
無
將存儲的字節解碼成列表
- 參數
bits_in_bytes – 需要解碼的字節
encoding – 字符集
- 回傳
解碼後的列表
用具體的字符集編碼input_list
- 參數
input_list – 輸入列表
encoding – 字符集
- 回傳
(用整數編碼的整數, 用比特表示的字符長度)
從列表獲取整個整數表示, 整個列表表示為大整數
- 回傳
整數表示
原子的獲取這個列表
- 回傳
列表
與get_int一致
原子比較和設置,比較自身和i的內容,如果相等,這個過程就是讀-修改-寫的操作,將n的內容寫入自身,如果不相等,是隻讀操作,自己的內容寫入i。
- 參數
i – 需要比較的列表
n – another bytes to be ready to write to self if comparision return True
- 回傳
當自身與i相等時就返回真,否則就返回錯誤。
原子獲取列表
- 參數
data – 新數據列表
- 回傳
原來的列表
3個指針之間兩兩交換值,將自己的值存入j然後將i存入自身
- 參數
i – 一個原子列表
j – 另一個原子列表
- 回傳
無
Atomically store contents from another list to the this list, if the other list is different with this one in size , the function will fail. You can use .size to check the space it use.
- 參數
i – 將要存儲值的另一個列表
- 回傳
無
Change the encoding of the string in the list, if the original size is not enough, it will elongate the string, if 8 bytes are not enough, it will fail.
- 參數
newencode – 新編碼,像是’utf-8』,』utf-16-le』
- 回傳
無
以整數表示來設置這個列表,整個列表將被當成一個大的整數。
- 回傳
無
設置這個列表的值,如果長於列表的原始長度,它需要擴展,就會失掉原子性,可以通過self.size來檢查空間佔用。
- 參數
data – 輸入列表
- 回傳
無
Function to finish the shift and add of the data prefix
- 參數
data_prefix – integer for the data_prefix
accumulate_length – total data length in bits accumulated so far
input_length – length of the data segment in bits
kind – sorts of data
- 回傳
(data_prefix, accumulate_length)
與get_list和set_list一致