Article View: borland.public.cppbuilder.nativeapi
Article #13562Re: Thread questions
From: Rob
Date: Fri, 03 Oct 2003 03:18
Date: Fri, 03 Oct 2003 03:18
71 lines
3574 bytes
3574 bytes
"Jonathan Starr" <starr@belsoft.com> wrote in message news:3f7b0c4e$1@newsgroups.borland.com... > I have two issues: > > 1. thread suspend/resume > > If a low-priority thread is suspended, and a high-priority thread > Resumes the low-pri thread but the high-priority thread continues > to run, under what cirsumstances will the low-pri thread actually > begin to execute? In rough terms, when there is no higher priority thread requiring CPU resources. In practice, it's s little more complex than that was the scheduler (at least under NT) is able to temporarily increase the priority of threads in some circumstances. > > If the high-pri thread, while continuing to run, calls a thread method of > the low-pri thread to Synchronize, will that make any difference (the > high-pri thread should be the UI thread, and would call the other > thread's method just to avoid duplicate code or complicated flow control). You're misunderstanding what Synchronize() does. It sends a message to the main UI thread and --- when that message is received --- the main UI thread calls the function involved. If Synchronize() is called from the main UI thread, it simply calls the function given. If Synchronize() is called by another thread, that thread is forced to wait until the main GUI thread has finished executing the function. > > Thanks in advance. > > PS What is happening is that the low-pri thread *appears* to begin > executing > at a random point while the high-pri thread is busy again. That is consistent. The high priority thread (your UI thread) is busy executing the function. The low priority thread resumes execution at whatever point it was suspended. > > 2. locking > > A thread may acquire a TCriticalSection a lock multiple times before > releasing it. The > lock maintains a counter internally. Not quite true. A thread is allowed to acquire a critical section more than once, and is guaranteed not to block if it already holds the critical section, and attempts to lock it again. There is no mention in the win32 documentation of any need to release a critical section multiple times if it has been entered multiple times. > > I had thought that if a thread acquired such a lock several times and > released it once, > it still held it - another thread would block trying to acquire it until > it was released > as many times as acquired. But I am seeing a case in which a single > release seems to > allow another thread to acquire the lock. > If yo uwant to do this, you may wish to consider using a semaphore type.
Technical Details
Message-ID:
<3f7cec02@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeeds.sol.net!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f7b0c4e$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,daa80f767a159c0c X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-10-02 20:40:08 PST From: "Rob" <nospam@nonexistant.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f7b0c4e$1@newsgroups.borland.com> Subject: Re: Thread questions Date: Fri, 3 Oct 2003 12:48:12 +0930 Lines: 74 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 NNTP-Posting-Host: 211.26.115.87 Message-ID: <3f7cec02@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1065151490 211.26.115.87 (2 Oct 2003 20:24:50 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeeds.sol.net!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail