ID:274011
 
Hey,
This might be an elementary question, so apologies in advance.
But after reading the reference on the background setting, compounded with never really seeing anyone use it, I'm a bit confused about it.

To me, the explanation of it in the reference is non-specific and obfuscated.

So hopefully someone can clear this up for me :)

* In more "human" terms, what does it do?
* When is it a good time to use it?
* When is a bad time to use it?
* What are the possible benefits?
* What are the negetive effects?
:-)
In response to Saucepan Man
Running in background will make the proc sleep at loop points if needed. Look up the sleep() proc. The reference on sleep gives more detail about this.
In response to Jemai1
No offnce with the title, but I know it does that. I said: I've read the reference.
And I know what sleep does.

If you glance at my original post, you'll see I have very specific questions. :)
From what I understand, this is an example of what it could do:

// This would probably cause a crash from infinite loop check.
// With background=1, it'll just slow down the server a ton,
// but it probably won't freeze anything.
proc/infinite_loop()
for(var/n in 1 to 100000)
some_CPU_hog()

// Without background=1, the server could freeze, wait a
// tick, and freeze again.
// With background=1, the server would freeze, but there
// would be tiny delays between each call of intense_proc()
// that would allow for other things to occur, resulting
// in lag, but not a big freeze.
proc/some_proc()
for()
intense_proc1()
intense_proc2()
intense_proc3()
sleep(1)


That's just what I got from the reference, at least. I have never used it before. I'm probably wrong.

If I'm not wrong though, I think one problem would be the timing inconsistency. The "other events occurring" could change things that the background proc uses.
In response to Kaiochao
My understanding isn't dissimilar to that.
I guess it would be used for non-priority procs.
e.g. a proc to refresh stats (depends on the pace of the game I suppose). or a proc that loops every so often, but doesn't need to restart at an exact moment?

I'm thinking of adding the setting to the login procedures, where I initialise various things?

By the sounds of it, I might like to use it as much as possible, but I don't want to overuse it and find out it ruins various aspects.
In response to Saucepan Man
The reference on sleep says:

If the ticker does intensive processing during each iteration, you probably want to run it in the background like this:

proc/Ticker()
set background = 1

Calling sleep() with a negative argument (such as sleep(-1)) causes it to do a backlog check. Only if other pending events have become backlogged will it sleep. This is similar to running in the background, but you manually control where the backlog checks are made. The difference between this and sleep(0) is that sleep(0) always sleeps the current procedure for as short a time as possible, whereas sleep(-1) only sleeps the current procedure if other scheduled events have become backlogged. Therefore, sleep(-1) will tend to run the current procedure at a higher priority with fewer interruptions. It is appropriate when there is a single task that needs to be done before anything else can happen, and you just want to make sure that network and user I/O are not terribly lagged in the process.


The underlined parts tells you when setting background is good to use and what it does.


The reference on background says:

Since the background procedure sleeps at unpredictable times, you must be aware that race conditions are possible if the background procedure interacts with variables modified by other procedures. It's still much safer than multi-threaded programs because the background procedure never interrupts other code; but other code may interrupt the background procedure.

The underlined part tells you the negative effect of running in background.

If you know when to use it and its negative effects, answers to the other questions would be pretty much self explanatory.