04.07.2011, 16:31
[Plugin] MultiThread
04.07.2011, 16:35
pawn Код:
// 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);
}
}
04.07.2011, 16:38
pawn Код:
// 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);
}
}
19.08.2011, 11:57
This Plugin is very nice. I try too make gamemode with this plugin
19.08.2011, 17:07
I think that this plugin is useful to check something and not to set. It can be used to create and call new powerful callbacks not more not less. Good work
19.08.2011, 17:37
so what this plugins does do?
19.08.2011, 18:16
19.08.2011, 19:01
19.08.2011, 19:05
That's not right. Pages 1-3 and perhaps even more are full of explanations why this plugin is highly impractical for PAWN/SA-MP and will end up crashing. It doesn't have much to do with timers anyways and it won't decrease memory usage for sure.
13.12.2012, 19:55
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?
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?
14.12.2012, 06:16
Quote:
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? |
14.12.2012, 07:26
This idea came to my mind this morning. Creating gamemode as a plugin and adding multithreading, will it work? Someone should try this.
24.04.2013, 21:28
Thank you! Very useful plugin.
24.04.2013, 23:38
Mutex lock doesn't work at random times. Thread still continues.
25.04.2013, 00:34
This plugin is bunk don't even waste your time with this nonsense.
25.04.2013, 11:58
Pawn is not thread-safe. This plugin is useful only if you want to crash your server.
29.01.2014, 16:32
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.
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.
29.01.2014, 16:39
Quote:
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 isn't threadsafe that's big reason why you shouldn't use it.
29.01.2014, 16:40
Quote:
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. |
Quote:
Pawn is not thread-safe. This plugin is useful only if you want to crash your server.
|
Basically, the SA:MP Server, RakNet nor Pawn is supposed to be run with multiple threads. With RakNet, if you push something to the client/the server at the same time, a crash is very probable or at least very unstable results.
Using this plugin would require so much caution and workarounds the speed you gain from it doesn't mean shit.
29.01.2014, 17:13
Quote:
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.
|
here's the code:
PHP код:
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;
}
Sorry for English.
« Next Oldest | Next Newest »
Users browsing this thread: 12 Guest(s)