Deutsch   English   Français   Italiano  
<62d347f5a0fa65e98ff2610a3e28a6012b83befb@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: fir <profesor.fir@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: logically weird loop
Date: Sun, 24 Nov 2024 11:20:48 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <62d347f5a0fa65e98ff2610a3e28a6012b83befb@i2pn2.org>
References: <0e1c6d2e74d44a715bf7625ca2df022d169f878a@i2pn2.org>
 <vhl32r$66a2$1@dont-email.me> <vhlspv$ahc9$10@dont-email.me>
 <5ffbd36e7c96003b8600afde056c3f06baee5531@i2pn2.org>
 <3ddedccc2d4a7ffea22f9b8f4de8f490c89d7b13@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 24 Nov 2024 10:20:51 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="3899945"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:91.0) Gecko/20100101
 Firefox/91.0 SeaMonkey/2.53.19
In-Reply-To: <3ddedccc2d4a7ffea22f9b8f4de8f490c89d7b13@i2pn2.org>
X-Spam-Checker-Version: SpamAssassin 4.0.0
Bytes: 4852
Lines: 110

fir pisze:
> fir pisze:
>> Lawrence D'Oliveiro pisze:
>>> On Wed, 20 Nov 2024 17:34:34 +0100, Janis Papanagnou wrote:
>>>
>>>> [*] A friend of mine just recently implemented the code frame for a
>>>> roguelike and followed the suggestion of an event based object-oriented
>>>> implementation; it worked well, he told me.
>>>
>>> The next step would be to use coroutines so the logic of a 
>>> longer-running
>>> task, which has to wait for other events at multiple points, can be
>>> written in a single linear stream without having to be fragmented into
>>> multiple callbacks.
>>>
>> i dont know to much on coroutines (what i knew i forgot as even my 
>> memory this year is terribly bad) or simule bot from some other
>> reasoning i know thet "call queue" is veru good thing
>>
>> possibly it may be better or at least equal in thiat coroutines or
>> what was in simula
>>
>> in basic call queue it gioes klike this afai
>>
>> for(int i=0; i<all; i++)
>>     add_queue foo(i);
>>
>> foo() are storred in queue so then can be run i pseudo parralel
>> mode at some point
>>
>> add_queue stores function adress and argument on stack like queue
>>
>> here in rogualike it would use this time variable also
>>
>>   DoAction(int i)
>>   {
>>     if(character[i].action_end > current_time) return;
>> // do nothing until time comes
>>
>> // time has come do something
>>    character[i],action_end += 300;
>>   add_queue DoAction(i); //put yourself on queue
>>
>>
>> }
>>
>> StartUp()
>> {
>> for(int i=0; i<all; i++) add_queue DoAction(i);
>>
>> }
>>
>> // in some code
>>   run_queue // queue may add soem alelemnts but also executed things 
>> are taken out of queue
>>
>> i guess it should be something like that
>>
>   i once said probably call queues should be a god way to do 
> multithreading becouse say you got a routine that calculates and draw a 
> vertical line of mandelbrot
> 
> for(int i=0; i<1000; i++)
>   add_queue1 draw_mandelbrot(i);
> 
> run_queue1;
> 
> as thoise calculations are independant the run_queue may execute queue
> (which is table of 1000 pointers and 1000 ints)
> pararelly in 1000 threads and its very easy
> 
> when items may be dependant soem could add them to queue but also
> store some tag (like group number) when eech group is independant versus 
> other groups so each group could be run separatelly on threads with 
> knowledge there is no conflict
> 
> 
> int group ;
> for(int i=0; i<1000; i++)
> {
> if(bot[i].x<300) group = 1;
> else if(bot[i].x>700) group = 2;
> else if(bot[i].x>400 && bot[i].x<600) group = 3;
> else group = 4;
> 
> add_queue1[group] run_bot(i);
> 
> 
> }

now its an error becouse when gorups 1 2 3 could run in parralel group 4 
can not (but someteimes when i post something i see an error but not 
bother to correct as its seen)

but becouse this is error it shows that eventually something more
could or shoudl be used than raw number of groups to encode a group
dependancy (like 4 can be executed after 1,2,3..but im not sure as for now

this queue hovever as i already said seem to me probably the most
conveniant way to d multithreading in c (some extended c) -
simply you feel queue and compiler or system simply runs it and it knows
the marked things are independant... so you get  easy and cklear on code 
side and easy and clear on hardware side
> 
> something like that but with better syntax.. it asumes bots act locally 
> on map and if are distant 100 distance they will not interract..than 
> those 4 groups can be run on 4 threads assumning nio collision is possible
> 
> 
> something like that