Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Cog Threads
Cog Threads
2003-07-22, 6:11 AM #1
This is to follow up the conversion on Hellcat's 'Trigger causes cog to stall' post.

I've done some more research and here are the results:

The number of threads that can run for one cog is five. The reason for the confusion before is because message calls (via the call keyword) will not work after the limit has been reached. But threads will still be created for event messages such as activated. An older thread will be killed for the new one to run.

But which thread will be killed? I'm fairly positive that the last created thread will be killed - the Cog's fifth thread.

SendTrigger() which was causing problems with DeathSythe's example, is not doing anything differently from other verbs like it. Other verbs that trigger cog events - and threads to be created for them - work the same way (such as SendMessage() and CreateThing()). The verb will finish only when all local cogs have received the event - and if they have a message handler for this event, they will start, and if not paused, finish the thread for the event before going back to the original cog.

At first, this seemed pretty wasteful to me - making one cog wait for others to respond when it tries to do something. But this is the way it has to work. If you send a message or trigger, you want the other cogs to have a chance to respond before you continue with the rest of your code.

Suppose you create five threads for a cog. In an example I had with a hotkey's activated message, I made the first four threads wait two seconds and the fifth one wait five seconds before printing a message that they'd finished. The first four could not wake from their sleep until the fifth one did. So I think this proves that JK looks only at the last created thread for a cog... If this highest thread is not ready to resume execution, JK goes on to the next cog. Maybe this explains why JK kills the last created thread when it reaches the thread limit and needs to create a new thread.

Threads will not be created for events that do not have message handlers in the code section - even if the messages are listed in the symbols section.

The purpose of Reset() is to kill all threads running in a cog except the current one - which I think has to be the last created. So Reset() kills all threads below its own.

Timers and Pulses use a thread only when their timer has expired and a thread is needed to run the code in their message. They don't need a thread when they're waiting to run. Pulses must be implemented in almost the same way as timers, they use similar verbs, similar cog flags, and they both have a time value stored with the cog. And since timers can be IDed, it would be very limiting if you could only have fewer than five timers and pulses at a time.

Most of the info above has been pretty well tested, but doubtless there will be discoveries that change some of it. I'd appreciate it if some of you could do some testing to verify this.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

[This message has been edited by SaberMaster (edited July 22, 2003).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-22, 2:09 PM #2
i cannot belive i just read all that, witch i will prooebly never use...

OMG, my eyes are hurting [http://forums.massassi.net/html/frown.gif]

------------------
I am pjb.
Another post......
another moment of my life wasted.....
at least i made a level.
PJB's JK page's

-the PJB jedi rule book-
rule one, "never trust a bartender with bad grammar"-kyle katarn in JO

Rule Two, "Gravity is a crule misstress" -kyle katarn in MotS, and the alternatior MK I in AJTD
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
2003-07-22, 9:12 PM #3
I know, I know.

It's my English, right? Not a single obvious typo.

While on the other hand, some people... [http://forums.massassi.net/html/rolleyes.gif]

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-23, 9:40 AM #4
Hmmm.... I am once again wondering how you tested it all and came up with this conclusion, but I don't really care. Just one more thing to add to DM and my memory. [http://forums.massassi.net/html/tongue.gif]

By the way, your English was good.

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-07-23, 12:06 PM #5
Quote:
<font face="Verdana, Arial" size="2">Originally posted by SaberMaster:
I know, I know.

It's my English, right? Not a single obvious typo.

While on the other hand, some people... [http://forums.massassi.net/html/rolleyes.gif]

</font>


STOP HITTING THAT DARNED "OWN PJB" BUTTON!!!!

------------------
I am pjb.
Another post......
another moment of my life wasted.....
at least i made a level.
PJB's JK page's

-the PJB jedi rule book-
rule one, "never trust a bartender with bad grammar"-kyle katarn in JO

Rule Two, "Gravity is a crule misstress" -kyle katarn in MotS, and the alternatior MK I in AJTD
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
2003-07-23, 2:52 PM #6
SM is reset used in any LEC cogs?

It seems like a logical conclusion, but I am amazed at how you can up with the idea though.

------------------
Team Battle.
Team Battle.
2003-07-25, 12:32 AM #7
No, LEC never used Reset(). I think they created it just to test with. If they ever had to use it, that would kind of imply they had problems with their scripting system.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

↑ Up to the top!