Re: Problem with function pointer



Sohail Ahmed Siddiqui wrote:

Hi,
i am working on a program which should connect to data server in one
thread, other threads will be used to update the UI and sorting data, in
some of the cases i have to use a function that should take int as
parameter and in some cases it has no parameter list. My class looks
some thing like this


class FunctionThread : public Threads
{
public:
typedef int (*Function)();
FunctionThread(Function function,
size_t stackSize=StackSize::DEFAULT,
Priority priority=Priority::INHERIT,
SchedulingPolicy schedpol=SchedulingPolicy::INHERIT,
const std::string& name="",
bool detached=true);
protected:
virtual int run();
private:
Function function_;

};

my function which enables me to make different threads i am using

FunctionThread::FunctionThread(Function function,
size_t stackSize,
Priority priority,
SchedulingPolicy schedpol,
const std::string& name, bool detached)
: Threads(stackSize, priority, schedpol, name, detached,1)
{}

int FunctionThread::run()
{
return (*function_)();
}

This works very well with functions that have no parameters, but if i
change typedef int (*Function)(); to typedef int (*Function)(int); some
how it doesn't seem to work at all, can some one please tell me how can
i change this so that it can take int as normal parameters?



Basically i want to use it like:
i wait till i get a transaction number from user and then i create a
thread and come back to UI while the thread works and gets the information

Transaction* trans = new Transaction(transNo);//this is the uint32_t

Transaction class has a worker thread from FunctionThread class

class Transaction
{
public:
Transaction(uint32_t transNo);
virtual ~Transaction();
static int transact()
private:
uint32_t transaction_;
FunctionThread worker_;
};

and
Transaction::Transaction(uint32_t transNo):worker_(StackSize::0x10000,
Priority::BACKGROUND,
SchedulingPolicy::FIFO,
"Transaction",false),
transaction_(transNo)
{
worker_.start();
}

Transaction::transact()
{
// connect to server and get the transaction from server
}

It does compile and execute normally, but no results are available, what i
think is maybe the thread is not getting started, but what is it not
starting i have no idea about it.

.



Relevant Pages

  • [NT] Subnet Bandwidth Management (SBM) Protocol subject to attack via the Resource Reservation Proto
    ... and use a Thawte Digital Certificate on your MSIIS web server. ... The resource reservation protocol (RSVP) is used within the Subnet ... a higher priority than the current RSVP server ... int nbytes); ...
    (Securiteam)
  • creating jobs programmatically causes deadlocks
    ... I'm using the transactional sproc below to create jobs in an automated ... On another server dropping just 10 of the trigger files causes ... The transaction is necessary since the ... DECLARE @ReturnCode INT ...
    (microsoft.public.sqlserver.server)
  • Re: Problem with function pointer
    ... i am working on a program which should connect to data server in one ... some of the cases i have to use a function that should take int as ... Priority priority=Priority::INHERIT, ... Transaction class has a worker thread from FunctionThread class ...
    (comp.programming.threads)
  • Re: Problem with function pointer
    ... how can i change this so that it can take int as normal parameters? ... Transaction class has a worker thread from FunctionThread class ... // connect to server and get the transaction from server ...
    (comp.programming.threads)
  • [2.6 patch] remove smbfs
    ... smbfs back in 2005 due to smbfs being unmaintained. ... for mounting to older SMB servers such as OS/2. ... -that turns any Unix host into a file server for DOS or Windows clients. ... -static int do_smb_getmountuid ...
    (Linux-Kernel)