Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #1455

Re: [Cross post: prog+asm+c]thread problem: one write, many read

From "io_x" <a@b.c.invalid>
Newsgroups comp.programming, alt.lang.asm, comp.lang.c
References <4f83d0ff$0$1377$4fafbaef@reader2.news.tin.it>
Subject Re: [Cross post: prog+asm+c]thread problem: one write, many read
Date 2012-04-10 08:42 +0200
Message-ID <4f83d522$0$1385$4fafbaef@reader2.news.tin.it> (permalink)
Organization TIN.IT (http://www.tin.it)

Cross-posted to 3 groups.

Show all headers | View raw


"io_x" <a@b.c.invalid> ha scritto nel messaggio 
news:4f83d0ff$0$1377$4fafbaef@reader2.news.tin.it...
> there is one buffer, only one thread write,
> many threads read that buffer
>
> what is the best solution for this problem for the x86 cpu?
> How do you useful express that using the C language? :) i'm not ot
>
> i think it is this: [because i believe it is possible many
> threads can read one peace of memory in the same time...]
>
> thread write:
> unsigned32bits   v=0, mem=0;
>
> mem=7;
> /* wait until v is 0 */
> Wait(&v, 0);
> change(buffer, len)
> mem=0;
>
> --------------
>
> threads read:
> /* wait until mem is 0 */
> Wait(&mem, 0);
because here it is possible the thread write change mem...

> atomic++(&v); /* if v==-1 seg fault :) */
> leggi(buffer, len)
> atomic--(&v);
>
> you see dead lock on all this? i not...


unsigned32bits   v=0, mem=0;

thread write:
/*atomic means if it is lock not write ...*/
 atomic_move(&mem, 7);
 /* wait until v is 0 */
 Wait(&v, 0);
 change(buffer, len)
 atomic_move(&mem, 0);


 threads read:
 /* wait until mem is 0 if is 0 lock mem
   and atomic increment v
   unlock mem
*/
 WaitIncrement(&mem, &v); /* if v==-1 seg fault :) */
 leggi(buffer, len)
 atomic--(&v);

Back to comp.programming | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

[Cross post: prog+asm+c]thread problem: one write, many read "io_x" <a@b.c.invalid> - 2012-04-10 08:24 +0200
  Re: [Cross post: prog+asm+c]thread problem: one write, many read "io_x" <a@b.c.invalid> - 2012-04-10 08:42 +0200
    Re: [Cross post: prog+asm+c]thread problem: one write, many read "io_x" <a@b.c.invalid> - 2012-04-10 10:34 +0200
      Re: [Cross post: prog+asm+c]thread problem: one write, many read "io_x" <a@b.c.invalid> - 2012-04-10 11:26 +0200
        Re: [Cross post: prog+asm+c]thread problem: one write, many read "io_x" <a@b.c.invalid> - 2012-04-10 12:56 +0200
          Re: [Cross post: prog+asm+c]thread problem: one write, many read "io_x" <a@b.c.invalid> - 2012-04-14 07:20 +0200
            Re: [Cross post: prog+asm+c]thread problem: one write, many read "io_x" <a@b.c.invalid> - 2012-04-15 08:04 +0200
  Re: [Cross post: prog+asm+c]thread problem: one write, many read "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-04-10 10:01 +0200
  Re: thread problem: one write, many read "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-04-13 17:13 -0700
    Re: thread problem: one write, many read "io_x" <a@b.c.invalid> - 2012-04-14 10:56 +0200

csiph-web