MFC Semaphore Usage Guide

Source: Internet
Author: User
Tags semaphore

DEMO Program: Testsemaphore_demo.rar

Source code: Testsemaphore_src.rar

---Key code is as follows---

voidCtestsemaphoredlg::onbnclickedbuttonthread1 () {//TODO: Add control notification handler code hereAfxBeginThread (Afx_threadproc) Thread1writea, This);}voidctestsemaphoredlg::onbnclickedbuttonthread2 () {//TODO: Add control notification handler code hereAfxBeginThread (Afx_threadproc) Thread2writeb, This);}voidctestsemaphoredlg::onbnclickedbuttonthread3 () {//TODO: Add control notification handler code hereAfxBeginThread (Afx_threadproc) Thread3writec, This);} UINT Ctestsemaphoredlg::thread1writea (lpvoid pparam) {Ctestsemaphoredlg* PThis = (ctestsemaphoredlg*) Pparam; PThis-Writea (); return 0;}voidCtestsemaphoredlg::writea () {CString str; G_semaphore.    Lock ();  for(intI=0; i<5; i++) {Sleep ( -);        M_editdisp.getwindowtext (str); STR+="A";            M_editdisp.setwindowtext (str); } g_semaphore. Unlock ();} UINT ctestsemaphoredlg::thread2writeb (lpvoid pparam) {Ctestsemaphoredlg* PThis = (ctestsemaphoredlg*) Pparam; PThis-Writeb (); return 0;}voidCtestsemaphoredlg::writeb () {CString str; G_semaphore.    Lock ();  for(intI=0; i<5; i++) {Sleep ( -);        M_editdisp.getwindowtext (str); STR+="B";            M_editdisp.setwindowtext (str); } g_semaphore. Unlock ();} UINT Ctestsemaphoredlg::thread3writec (lpvoid pparam) {Ctestsemaphoredlg* PThis = (ctestsemaphoredlg*) Pparam; PThis-Writec (); return 0;}voidCtestsemaphoredlg::writec () {CString str; G_semaphore.    Lock ();  for(intI=0; i<5; i++) {Sleep ( -);        M_editdisp.getwindowtext (str); STR+="C";            M_editdisp.setwindowtext (str); } g_semaphore. Unlock ();}

With this tutorial you can quickly learn how to use the Semaphore in MFC!

MFC Semaphore Usage Guide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.