Newsgroups: comp.programming.threads
From: k...@ashi.footprints.net (Kaz Kylheku)
Date: Sun, 22 Apr 2001 19:22:53 GMT
Local: Sun, Apr 22 2001 3:22 pm
Subject: Re: A theoretical question on synchronization
On Sun, 22 Apr 2001 01:38:33 -0400, Timur Aydin <tay...@snet.net> wrote: This is far from elegant, because the queue data structure already knows the >Kaz Kylheku wrote: >> However, the nature and variety of the objects provided by Win32 leaves >> with condition variables because they have no programmer visible state. >One example where using a semaphore provides an elegant solution is a number of messages either implicitly or with an extra counter of its own. Usually, what is most relevant is whether or not the queue is empty. So the semaphore is coding redundant information. Note that at times, this information will be out of sync. For example, say you have this sequence of actions: lock(); In between the append and signal operation, the queue has N+1 items, A semaphore has an internal lock which protects incremnts and decrements So really, the samephore provides only a kludgy solution to synchronization Also note that a sempaphore object can be trivially implemented using a mutex, >A thread that This can be inefficient compared to just waking up, noting that there >processes these messages can just wait on the semaphore and will wake >upprecisely as many times as there are messages in the queue. are messages to be processed and removing all of them. >This problem could also have been resolved with a win32 style event object, Note that an (auto reset) event is nothing more than a binary semaphore >but it would not be as simple and intuitive as above and this would also >lead to situations where the thread would unnecessarily wake up and find >nothing in the message queue. which counts between the unsignaled and signaled states (effectively 0 and 1). >This same problem would be very difficult to solve with a POSIX condition Hardly at all! >object. >Because it is stateless, a thread has to be waiting at the instant Do you have even the slightest clue on how condition variables are used >that the condition is signaled, otherwise the thread would not notice. >Say correctly or are you just guessing based on reading about them in a manual page? You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||