TThread Problem

I am trying to write a script that will remotely open up a TSocket connection using expect. The expect code works, but I can’t get the threads to work (this is my first time using threads). The attached script is obviously not finished.

From Lxplus:

echo $ROOTSYS
/afs/cern.ch/sw/lcg/external/root/5.15.02/slc4_amd64_gcc34/root

result:

[code]
root [0] .L Sockettest.cpp
root [1] Sockettest(9090)

Error in TMutex::UnLock: thread 182932320512 tries to unlock unlocked mutex
start

*** Break *** segmentation violation
[/code]
Sockettest.cpp (1.04 KB)

Hi,

You must compile the code (use ACLiC) to be able to use threads.
So instead of

root [0] .L Sockettest.cpp root [1] Sockettest(9090)
Use:

root [0] .L Sockettest.cpp++ root [1] Sockettest(9090)
It has also the advantage of showing the errors you have in your code (see your code modified below).

[code]#include “TError.h”
#include “TMessage.h”
#include “TServerSocket.h”
#include “TSystem.h”
#include “TThread.h”
#include

typedef struct {
Int_t portnum;
TString hostname;
} clarg_t;

void *startserver(void *sargs){
clarg_t *args=(clarg_t *)sargs;
Int_t nport=args->portnum;
args->hostname= gSystem->HostName();
TServerSocket *ss=new TServerSocket(nport,kTRUE);
TSocket *socket= ss->Accept();
socket->Send(“goljlkll”);
char str[32];
socket->Recv(str,32);
return 0;
}

void * startclient(void *clargs)
{
clarg_t *args=(clarg_t *)clargs;
Int_t nport=args->portnum;
TString str = args->hostname;

gSystem->Exec(Form("./OpenLxplusROOTClient.sh %s %i",str.Data(),nport));
return 0;
}

void Sockettest(Int_t portnumber)
{
//gSystem->Load("/usr/lib/libpthread.so");
gSystem->Load(“libThread”);
clarg_t testclarg;
testclarg.portnum = portnumber;
TThread *ths=new TThread(“Server”,startserver,(void *) &testclarg);
TThread *thcl=new TThread(“Client”,startclient,(void *) &testclarg);
std::cout<<“start”<<std::endl;
ths->Run();
gSystem->Sleep(20);
thcl->Run();
std::cout<<“done”<<std::endl;
}[/code]

And please take a look at tutorials:
for threads: in $(ROOTSYS)/tutorials/thread
for sockets: in $(ROOTSYS)/tutorials/net

Cheers,
Bertrand.