国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

怎樣做電商網(wǎng)站社群營銷案例

怎樣做電商網(wǎng)站,社群營銷案例,品牌微信網(wǎng)站開發(fā),國外的做外包項目的網(wǎng)站rtc::Thread介紹 rtc::Thread類不僅僅實現(xiàn)了線程這個執(zhí)行器(比如posix底層調(diào)用pthread相關(guān)接口創(chuàng)建線程,管理線程等),還包括消息隊列(message_queue)的實現(xiàn),rtc::Thread啟動后就作為一個永不停止的event l…

rtc::Thread介紹

rtc::Thread類不僅僅實現(xiàn)了線程這個執(zhí)行器(比如posix底層調(diào)用pthread相關(guān)接口創(chuàng)建線程,管理線程等),還包括消息隊列(message_queue)的實現(xiàn),rtc::Thread啟動后就作為一個永不停止的event loop,沒有任務(wù)待執(zhí)行就阻塞等待,添加任務(wù)后就喚醒event loop,去執(zhí)行任務(wù),周而復(fù)始,直到調(diào)用stop退出event loop,退出線程(線程join)。

在WebRTC內(nèi)部,可以將消息隊列等同于event loop,消息隊列為空,就進行阻塞等待。


class RTC_LOCKABLE Thread : public MessageQueue {

Thread關(guān)鍵接口

public:// Starts the execution of the thread.bool Start(Runnable* runnable = nullptr);// Tells the thread to stop and waits until it is joined.// Never call Stop on the current thread.  Instead use the inherited Quit// function which will exit the base MessageQueue without terminating the// underlying OS thread.virtual void Stop();virtual void Send(const Location& posted_from,MessageHandler* phandler,uint32_t id = 0,MessageData* pdata = nullptr);// Convenience method to invoke a functor on another thread.  Caller must// provide the |ReturnT| template argument, which cannot (easily) be deduced.// Uses Send() internally, which blocks the current thread until execution// is complete.// Ex: bool result = thread.Invoke<bool>(RTC_FROM_HERE,// &MyFunctionReturningBool);// NOTE: This function can only be called when synchronous calls are allowed.// See ScopedDisallowBlockingCalls for details.template <class ReturnT, class FunctorT>ReturnT Invoke(const Location& posted_from, FunctorT&& functor) {FunctorMessageHandler<ReturnT, FunctorT> handler(std::forward<FunctorT>(functor));InvokeInternal(posted_from, &handler);return handler.MoveResult();}// ProcessMessages will process I/O and dispatch messages until://  1) cms milliseconds have elapsed (returns true)//  2) Stop() is called (returns false)bool ProcessMessages(int cms);protected:// Blocks the calling thread until this thread has terminated.void Join();

MessageQueue關(guān)鍵接口

public:
virtual void Quit();// Get() will process I/O until:
//  1) A message is available (returns true)
//  2) cmsWait seconds have elapsed (returns false)
//  3) Stop() is called (returns false)
virtual bool Get(Message* pmsg,int cmsWait = kForever,bool process_io = true);virtual void Post(const Location& posted_from,MessageHandler* phandler,uint32_t id = 0,MessageData* pdata = nullptr,bool time_sensitive = false);
virtual void PostDelayed(const Location& posted_from,int cmsDelay,MessageHandler* phandler,uint32_t id = 0,MessageData* pdata = nullptr);
virtual void PostAt(const Location& posted_from,int64_t tstamp,MessageHandler* phandler,uint32_t id = 0,MessageData* pdata = nullptr);virtual void Dispatch(Message* pmsg);
virtual void ReceiveSends();protected:
void WakeUpSocketServer();MessageList msgq_ RTC_GUARDED_BY(crit_);
PriorityQueue dmsgq_ RTC_GUARDED_BY(crit_);

線程啟動Start

調(diào)用Start接口啟動底層線程,同時進入一個永不停止的event loop(除非調(diào)用Stop接口)
流程如下:
Start->pthread_create->PreRun->Run

void Thread::Run() {ProcessMessages(kForever);
}

在這里插入圖片描述
最終通過Get接口獲取消息去執(zhí)行(Dispatch),Get獲取不到消息就是進入阻塞狀態(tài)(wait),等待有消息后被喚醒。
在這里插入圖片描述

線程消息隊列處理消息的流程ProcessMessage

  • 1、處理從其他線程發(fā)送的要在本線程去執(zhí)行的消息,即同步調(diào)用
    在這里插入圖片描述

接收者線程處理流程:
在這里插入圖片描述在這里插入圖片描述

發(fā)送者線程流程:
在這里插入圖片描述

  • 2、處理延遲消息(存儲在優(yōu)先級隊列)
    延遲消息是通過PostDelayed和PostAt接口調(diào)用然后push到優(yōu)先級隊列中(dmsgq_,小根堆)
    在這里插入圖片描述

  • 3、異步消息(存儲在普通隊列里)
    延遲消息是通過Pos接口調(diào)用然后push到普通隊列中(msgq_)
    在這里插入圖片描述

任務(wù)提交方式(Invoke/Post)

webrtc內(nèi)部消息其實是對待執(zhí)行任務(wù)的封裝,消息和任務(wù)可以認為是一個意思

消息要繼承MessageHandler,實現(xiàn)OnMessage

class MessageHandler {public:virtual ~MessageHandler();virtual void OnMessage(Message* msg) = 0;protected:MessageHandler() {}private:RTC_DISALLOW_COPY_AND_ASSIGN(MessageHandler);
};

因為執(zhí)行消息,實際上就是執(zhí)行OnMessage(詳見Dispatch接口實現(xiàn))
在這里插入圖片描述

上一章節(jié)其實已經(jīng)把三種任務(wù)提交方式介紹過了
1、同步阻塞調(diào)用(Send,Invoke)
Invoke其實最終也是調(diào)用Send,Invoke是個函數(shù)模版,可以非常方便在目標執(zhí)行線程執(zhí)行函數(shù)然后獲得返回值,Invoke實現(xiàn)如下:

  // Convenience method to invoke a functor on another thread.  Caller must// provide the |ReturnT| template argument, which cannot (easily) be deduced.// Uses Send() internally, which blocks the current thread until execution// is complete.// Ex: bool result = thread.Invoke<bool>(RTC_FROM_HERE,// &MyFunctionReturningBool);// NOTE: This function can only be called when synchronous calls are allowed.// See ScopedDisallowBlockingCalls for details.template <class ReturnT, class FunctorT>ReturnT Invoke(const Location& posted_from, FunctorT&& functor) {FunctorMessageHandler<ReturnT, FunctorT> handler(std::forward<FunctorT>(functor));InvokeInternal(posted_from, &handler);return handler.MoveResult();}void Thread::InvokeInternal(const Location& posted_from,MessageHandler* handler) {TRACE_EVENT2("webrtc", "Thread::Invoke", "src_file_and_line",posted_from.file_and_line(), "src_func",posted_from.function_name());Send(posted_from, handler);
}

調(diào)用方式舉例:

bool result = thread.Invoke<bool>(RTC_FROM_HERE, &MyFunctionReturningBool);

2、異步非阻塞延遲調(diào)用
PostDelayed和PostAt

3、異步非阻塞調(diào)用
Post

線程退出Stop

void Thread::Stop() {MessageQueue::Quit();Join();
}void MessageQueue::Quit() {AtomicOps::ReleaseStore(&stop_, 1);WakeUpSocketServer();
}void Thread::Join() {if (!IsRunning())return;RTC_DCHECK(!IsCurrent());if (Current() && !Current()->blocking_calls_allowed_) {RTC_LOG(LS_WARNING) << "Waiting for the thread to join, "<< "but blocking calls have been disallowed";}#if defined(WEBRTC_WIN)RTC_DCHECK(thread_ != nullptr);WaitForSingleObject(thread_, INFINITE);CloseHandle(thread_);thread_ = nullptr;thread_id_ = 0;
#elif defined(WEBRTC_POSIX)pthread_join(thread_, nullptr);thread_ = 0;
#endif
}
http://m.aloenet.com.cn/news/34285.html

相關(guān)文章:

  • 法人變更在哪個網(wǎng)站做公示重慶森林為什么不能看
  • 知名的網(wǎng)站制作武漢網(wǎng)絡(luò)推廣優(yōu)化
  • bazien wordpress旅游企業(yè)seo官網(wǎng)分析報告
  • php商城網(wǎng)站建設(shè)多少錢百度推廣營銷怎么做
  • 織夢整形醫(yī)院網(wǎng)站開發(fā)江門網(wǎng)站優(yōu)化公司
  • 駕校網(wǎng)站建設(shè)關(guān)鍵詞北京網(wǎng)站優(yōu)化哪家好
  • java做網(wǎng)站與php做網(wǎng)站鏈接提交
  • 開個網(wǎng)站做上海關(guān)鍵詞優(yōu)化推薦
  • 知名網(wǎng)站建設(shè)查排名官網(wǎng)
  • 延吉網(wǎng)站優(yōu)化網(wǎng)絡(luò)營銷的策略包括
  • 怎么樣做網(wǎng)站的目錄結(jié)構(gòu)查找網(wǎng)站
  • 麗江網(wǎng)絡(luò)推廣廊坊seo推廣公司
  • 今天天津最新通告南寧seo優(yōu)化
  • 怎樣建設(shè)公司網(wǎng)站小程序seo服務(wù)商排名
  • 網(wǎng)站建設(shè)項目報價網(wǎng)站歷史權(quán)重查詢
  • 網(wǎng)站改版 百度北京seo優(yōu)化技術(shù)
  • 網(wǎng)站被入侵后需做的檢測 1關(guān)鍵詞分為哪幾類
  • 做網(wǎng)站的軟件公司長尾關(guān)鍵詞挖掘愛站網(wǎng)
  • 國家水資源監(jiān)控能力建設(shè)網(wǎng)站semir是什么牌子衣服
  • 黃岡黃頁寧波網(wǎng)絡(luò)推廣seo軟件
  • 珠海營銷營網(wǎng)站建設(shè)公司培訓(xùn)機構(gòu)不退費最有效方式
  • 深圳網(wǎng)站建設(shè) 推薦xtdseo百度系app有哪些
  • 做網(wǎng)站算軟件開發(fā)么長尾關(guān)鍵詞在線查詢
  • 建設(shè)網(wǎng)站開通網(wǎng)線多少錢資源網(wǎng)站優(yōu)化排名優(yōu)化
  • 北京網(wǎng)站推廣|網(wǎng)站制作|網(wǎng)絡(luò)推廣|網(wǎng)站建設(shè)7個湖北seo網(wǎng)站推廣策略
  • 沈陽微信網(wǎng)站搜索引擎優(yōu)化的要點
  • 三亞網(wǎng)站建設(shè)哪家好760關(guān)鍵詞排名查詢
  • 做網(wǎng)站用win還是li注冊百度賬號
  • 湖南建設(shè)人力資源官方網(wǎng)站萬能軟文模板
  • 廣西做網(wǎng)站口碑營銷方案