|
Fro1sha, when I use DestroyThread, it shuts down my server - is there any way to stop the thread from continuing without shutting it down?
|
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
#include <a_samp>
#include <thread>
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
new tickid, tick2id, ticknumber = 0, tick2number = 0;
public OnGameModeInit()
{
tickid = CreateThread( "MyFunction" );
tick2id = CreateThread( "MyFunction2" );
}
public OnGameModeExit()
{
DestroyThread( tickid );
DestroyThread( tick2id );
}
forward MyFunction(threadid);
public MyFunction(threadid)
{
ticknumber++;
if(ticknumber == 10) {
printf( "Closing Thread (%d)", tickid );
LockThread( threadid );
} else {
SleepThread( 1000 );
printf( "tick %d: %d", tickid, ticknumber);
}
}
forward MyFunction2(threadid);
public MyFunction2(threadid)
{
tick2number++;
if(tick2number == 10) {
printf( "Closing Thread (%d)", threadid );
LockThread( tick2id );
} else {
SleepThread( 2000 );
printf( "tick %d: %d", tick2id, tick2number);
}
}
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
#include <a_samp>
#include <thread>
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
new tickid, tick2id, ticknumber = 0, tick2number = 0;
public OnGameModeInit()
{
tickid = CreateThread( "MyFunction" );
tick2id = CreateThread( "MyFunction2" );
}
public OnGameModeExit()
{
DestroyThread( tickid );
DestroyThread( tick2id );
}
forward MyFunction(threadid);
public MyFunction(threadid)
{
ticknumber++;
if(ticknumber == 10) {
printf( "Closing Thread (%d)", tickid );
LockThread( threadid );
} else {
SleepThread( 1000 );
printf( "tick %d: %d", tickid, ticknumber);
}
}
forward MyFunction2(threadid);
public MyFunction2(threadid)
{
tick2number++;
if(tick2number == 10) {
printf( "Closing Thread (%d)", threadid );
LockThread( tick2id );
} else {
SleepThread( 2000 );
printf( "tick %d: %d", tick2id, tick2number);
}
}
|
SA-MP server runs ONE thread, in which, timers, functions, and other stuff take action.
This is a Multi-Thread, helps you create many threads, in which, timers will work, without consuming much memory. I think I got it right? |
|
I readed all topic, I was so impressed when I read the topic name. I know, now I get flamed for bumping old thread, but I've got some unclear questions.
Is it possible to use this without having any issues? Is it possible to write multitasking plugin, but it's very hard or it's totally impossible? |
|
There is no way unless you got the source of sa-mp and can edit it to make it multithread-compatible. (and you'd have to wedit pawn aswell because, as far as I know it has no multithread support.)
|
|
I don't know what is wrong with you guys.
This plugin increases the power of the scripter. You can create background processes with this plugin so user won't have to wait for the loop which does regulary work for all users or any function that has heavy calculations to be done. If you call the loop or the function with the plugin, the server processes users command and the loop and the function at the same time and everything is completed in less time. Say me a reason to not to use this plugin I'll Shift+Delete my entire script. |
|
I don't know what is wrong with you guys.
This plugin increases the power of the scripter. You can create background processes with this plugin so user won't have to wait for the loop which does regulary work for all users or any function that has heavy calculations to be done. If you call the loop or the function with the plugin, the server processes users command and the loop and the function at the same time and everything is completed in less time. Say me a reason to not to use this plugin I'll Shift+Delete my entire script. |
|
Pawn is not thread-safe. This plugin is useful only if you want to crash your server.
|
|
By "PAWN is not threadsafe" we mean that running two threads within PAWN will corrupt data and make you loose information, run code that shouldn't be run, and then just crash.
|
new string[180];
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
format(string,sizeof(string),"Bla bla bla %s",blablabla);
SendClientMessage(playerid,RED,string);
return 1;
}
else if (strcmp("/mycommand2", cmdtext, true, 10) == 0)
{
format(string,sizeof(string),"Bla bla bla 2 %s",blablabla2);
SendClientMessage(playerid,RED,string);
return 1;
}
return 0;
}