Steven Woody wrote:
> On Oct 1, 5:08 pm, Zeppe <ze...@remove.all.this.long.comment.yahoo.it>
> wrote:
>> Steven Woody wrote:
>>> Hi,
>>> i am writting some classes, those need to work in both linux and
>>> windows. in my problem, there are mutiple productor and one
>>> consumer, productors each in a different thread are trying to append a
>>> byte to a shared buffer while the consumer in the main thread will
>>> remove one byte every some milliseconds.
>>> the productors has to wait if the buffer is read/write by other
>>> productors or the consumer, on the other hand, the consumer should
>>> immediately exit if the buffer is read/write by any productor.
>>> i am thinking, for the problem above, the semaphore can help. is
>>> there a portable semaphore implementation in C++ ( if not, in C )?
>>> thanks in advance.
>> A good idea in my opinion would be to look for the boost thread library.
>> It's not standard, but it's portable enough. It hasn't got semaphores,
>> though. However, I think a mutex solution can be devised easily and it
>> may be less error-prone.
>>
>> Regards,
>>
>> Zeppe
>
> ok, i go to study it. but i have one thing in doubt: semaphores or
> other mutex solutions should have to dependent on some sort of 'atomic
> operation' which should be OS-dependent, am i right? so how can a
> library implement it without depends on OS?
Yes, it is OS-dependent, and a library can implement it with
#ifdef something
// implementation for window
#else
// implementation for linux
#endif
>
> ps. how to implement atomic oepration in Linux and how to implement it
> in Windows? thanks.
>
>
You are better asking those questions in another news group. Maybe
comp.programming.threads