Article View: borland.public.cppbuilder.nativeapi
Article #1315Differences between Semaphore and Mutex
From: Danny
Date: Sun, 16 Sep 2007 07:08
Date: Sun, 16 Sep 2007 07:08
44 lines
1779 bytes
1779 bytes
Hi all, I must to synchronize two threads, but I've a problem with the mutex procedures. In the following code I've used the semaphores...: 1# thread HANDLE h=::CreateSemaphore(NULL,0,1,"PddSem"); ....... execute the #2 thread ....... ::WaitForSingleObject(h,INFINITE); ::CloseHandle(h); 2# thread ....... HANDLE h=::OpenSemaphore(SEMAPHORE_ALL_ACCESS,false,"PddSem"); ::ReleaseSemaphore(h,1,NULL); ::CloseHandle(h); ...ans work all fine, but if I use the mutexs...: 1# thread HANDLE h=::CreateMutex(NULL,true,"PddMut"); ....... execute the #2 thread ....... ::WaitForSingleObject(h,INFINITE); ::CloseHandle(h); 2# thread ....... HANDLE h=::OpenMutex(MUTEX_ALL_ACCESS,false,"PddMut"); ::ReleaseMutex(h); ::CloseHandle(h); ...the #1 thread don't wait the #2 thread. Currently I've solved my problem with the semaphores, but someone could explain me the differences. Thanks
Technical Details
Message-ID:
<46ecd663@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,6b2ce248fe32d850,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Danny" <danny2912@libero.it> From: "Danny" <danny2912@libero.it> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Differences between Semaphore and Mutex Date: Sun, 16 Sep 2007 09:08:29 +0200 Lines: 46 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 NNTP-Posting-Host: 151.49.233.85 Message-ID: <46ecd663@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1189926499 151.49.233.85 (16 Sep 2007 00:08:19 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail