新聞中心
1、流程

創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:做網(wǎng)站、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶(hù)于互聯(lián)網(wǎng)時(shí)代的高州網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
(1)先嘗試去獲取互斥量mutex,如果獲取失敗,則循環(huán)監(jiān)控locked狀態(tài),等待持有鎖的線程釋放鎖
(2)如果獲取到互斥量,將locked狀態(tài)置1,表示鎖已被該線程持有,其他線程需要等待,然后釋放互斥量,讓其他線程有機(jī)會(huì)進(jìn)入臨界區(qū)等待上鎖
2、實(shí)例
int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
{
int success;
pthread_lock *thelock = (pthread_lock *)lock;
int status, error = 0;
status = pthread_mutex_lock( &thelock->mut );
success = thelock->locked == 0;
if ( !success && waitflag ) {
while ( thelock->locked ) {
status = pthread_cond_wait(&thelock->lock_released,
&thelock->mut);
}
success = 1;
}
if (success) thelock->locked = 1;
status = pthread_mutex_unlock( &thelock->mut );
if (error) success = 0;
return success;
}以上就是python獲取GIL鎖的流程,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)推薦:python教學(xué)
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
本文名稱(chēng):創(chuàng)新互聯(lián)Python教程:Python獲取GIL鎖的流程
網(wǎng)頁(yè)地址:http://www.5511xx.com/article/dpcshsj.html


咨詢(xún)
建站咨詢(xún)
