Re: Problem with function pointer
- From: Sohail Ahmed Siddiqui <sohail@xxxxxxxxxxxxxxx>
- Date: Fri, 05 May 2006 20:17:58 +0200
Ulrich Eckhardt wrote:
Sohail Ahmed Siddiqui wrote:
[...] 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);
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?
1. Provide a sensible error description. You basically said "I have this
code and it works, I want to change it in some way which I'm not showing
you and then it doesn't work". How should we know what exactly you did and
how you want to use it? Also, please remove everything that is not
necessary to demonstrate the problem (I dare say you will quickly find
that it even has nothing to do with threads but is just a C++ problem).
2. If you want universal functions that can carry any kind of parameter
flexibly, take a look at Boost.Functional and Boost.Bind. While you're
there, you could also take a look at Boost.Thread, although that doesn't
give you access to scheduling policies or the stacksize, so might not be
powerful enough for your case.
Uli
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.
Sohail
.
- References:
- Problem with function pointer
- From: Sohail Ahmed Siddiqui
- Re: Problem with function pointer
- From: Ulrich Eckhardt
- Problem with function pointer
- Prev by Date: Re: Problem with function pointer
- Next by Date: Re: when multiple threads are waiting on a mutex, which one will acquire the lock first?
- Previous by thread: Re: Problem with function pointer
- Next by thread: Re: Problem with function pointer
- Index(es):
Relevant Pages
|