Pthreads

Hi group.
I'm a recent graduate in CS and have done all my past programming in C++ on
a Solaris machine. However, I recently installed Visual C++. In an effort
to get accustomed to it I tried bringing over some of my old UNIX code to
get it to work on the Windows machine. The problem that I had was that
pthreads were not implemented. However, I downloaded the package that is
supposed to have everything needed to implement the pthread class.
My question is where do I put the files in order to be able to get things
going smoothly? I put the .h files into the Include folder, which is where
I assume those go. I put the .lib file in the Lib folder. I put the .dll
file in the directory c:\WINNT (Win2kPro). To me these locations for the
files made sense. Is
there something I'm obviously not doing right? The
reason I ask is because my program compiles cleanly, however, when I try to
create the .exe it fails in linking with the following error messages:
Linking...
3Thread.obj : error LNK2001: unresolved external symbol __imp__pthread_join
3Thread.obj : error LNK2001: unresolved external symbol
__imp__pthread_create
Debug/3Thread.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Since my program works fine in UNIX and compiles cleanly in Visual C++ I'm
lead to believe that I did something wrong with the placement of the above
mentioned files. Anyone out there gotten pthreads running fine on their
systems? Or is it my code that is wrong? Thanks for any help that anyone
could provide!
Brian

"Spivot" wrote in message
news:[email protected]..
> Hi, Brian.
> I met same problem when my compiller found other files with same
> name in another folder...
> Where did U put headers? I recomend use setting in VC++
> Options->Directories, move folder with .h and lib at top.
>
> And another variant. Did U connect(link) lib in your project?
>
> Hope that it help U
Thanks for the suggestions. I didn't link the library to my project. I
didn't realize that I had to do that, like I said new to Visual C++
Thanks a ton though, it worked and I got the program running with standard
style posix threads I guess it would've made too much sense for MS to
include these originally

Similar Messages

  • Bug in Oracle lib: popen failed with pthread in Redhat 6.1

    Dear Oracle developers,
    I need your help on this. I have used c and pthread in Redhat 6.1 and the moment I called popen, it dies. This happens only if I link some Oracle libraries. I am using ProC.
    The Oracle libraries in question are
    -lsql -L/export/ora01/app/oracle/product/8.0.5/lib -lc -lclntsh -lcommon -lcore4 -lnlsrtl3
    I have tested this with very simple pthread
    programs from Oreily even. The program dies at the call of popen if I have linked these libraries. Else it will work fine.
    If anyone has a solution to that, please let me know. My email is [email protected]
    Thanks.

    Hi kawollek,
    Thanks for the reply.
    But when i tried with the example provided. I am unable to connect to oracle. it gives the error 0ra-03114 not connected to oracle.
    How do i give the host string in oracle or dsn in the programe to connect to the database.
    If u have tried please help me.....
    Thanks & regards
    Rama Raju D.S

  • Problem with pthread compilation

    hi all...
    im trying to compile ccid-1.0.0 on solaris10 x86 and im getting problems that
    configure error : pthread
    my compiler version is::
    bash-3.00# which cc
    /opt/SUNWspro/prod/bin/cc
    bash-3.00# cc -V
    cc: Sun C 5.7 2005/01/07
    usage: cc [ options] files. Use 'cc -flags' for details
    i installed sunstudio11 prior to this and also pcsclite-1.3.0 and
    libmusclecard-1.3.1. They gave me no probs.
    ./configure --prefix=${MSCPFX}
    --enable-usbdropdir=${MSCPFX}/pcsc/drivers --enable-libusb
    and the o/p is :
    checking for memcpy... yes
    checking for dlopen in -ldl... no
    checking whether pthreads work with -pthread... no
    checking whether pthreads work with -pthreads... no
    checking for the pthreads library -lpthread... no
    checking whether pthreads work with -mt... no
    checking for the pthreads library -lpthreads... no
    checking whether pthreads work without any flags... no
    checking whether pthreads work with -Kthread... no
    checking whether pthreads work with -kthread... no
    checking for the pthreads library -llthread... no
    checking whether pthreads work with -pthread... no
    checking whether pthreads work with -pthreads... no
    checking whether pthreads work with -mthreads... no
    checking for the pthreads library -lpthread... no
    checking whether pthreads work with --thread-safe... no
    checking whether pthreads work with -mt... no
    configure: error: POSIX thread support required
    pls suggest me some way to get out of it.

    checking for the pthreads library -lpthread... no
    checking whether pthreads work with -mt... noOne of those should work.
    pls suggest me some way to get out of it.With such configure scripts, there's usually a resulting 'config.log'. In this, you should be able to see exactly what configure is trying to achieve, and why it is failing.
    Paul

  • Memory leak using pthreads on Solaris 7

    I'm on Solaris 7
    uname -a:
    SunOS zelda 5.7 Generic_106541-18 sun4u sparc SUNW,Ultra-250
    compiling with g++ (2.95.2)
    purify 5.2
    I consistently get memory leaks related (apparently)
    to the pthreads lib. I've set the error reporting chain length to 30 (way big), the start of the chain in every case starts with threadstart [ libthread.so.1 ]
    when I end my process, I Join the threads before deleting them. What else can I do to get rid of these leaks?
    thanks,
    rich

    is it worth upgrading to a 64 bit OS with more ram.
    Well you're talking a fairly hefty investment in fact your best bets buying a new machine at that point since the motherboard would need to be upgraded as well as memory and OS.
    Now  I run on a 64 bit OS 12 gigs of ram, but i love my plug-ins, and most are 32 bit, so you would still be using the 32 bit Photoshop if you want the majority of all plugins for photoshop to work. Well while the 32 bit version still have the memory limitations on how much memory it can use, Because its in the 64 bit OS, you have available the full amount of that limitation available to the application.
    I can run several different memory intensive applications at one time and normally not have an issue.  I say normally cause, sometimes i will crash my graphics driver if i open one too many 3d apps hooked into the Nvidia drivers.
    I normally only reboot maybe once a week.
    So in short, would it help you to be able to go 64 bit with more ram, Most Certainly even more so if you could care less about plug-ins and want to use the 64 bit version. should you go to 16 gigs of ram.. That depends on your budget really,
    Personally I always plan to upgrade when I build my systems, Putting in the largest chips you can with out filling all the slots leaving room for upgrading if needed. that way you're not filling all your slots with cheaper lower memory ram that you would have to replace them all to upgrade.
    Hope this helps a bit

  • Implementing pthreads in Pro*C

    Hi All,
    I'm trying to create a multithreaded Pro*C program, it goes like
    1. Main thread connects to database and does some DB operations.
    2. On specified condition creates a detached Pthread to perform some DB
    transactions.
    3. Child thread connects to the DB again to perform thread specific DB
    operation.
    My doubt here is:
    1.Does child thread share the same DB session of parent thread?
    2.Connecting to DB again in child thread can cause a problem to parent thread's
    session ?
    Regards,
    Vishwa....

    You can find an example of this in the Pro*C docs and in the Pro*C demo code; I think it's called multithrd.pc or something like that.

  • [pthread - Solaris 8] pthread_mutex_lock / pthread_mutex_unlock weird pb

    Hi all,
    I actually have the current problem : I create 2 threads, one thread works a lot and spend most of its time in the critical session and the other one sleeps most of the time (outside the critical section)
    The problem is : the slow thread never get the mutex so it never access to the critical session and the big worker seems to unlock/relock to fast to let the other thread work.
    The problem occurs under Solaris 8 but I have no problem under Solaris 10 (most of our workstations still work under Solaris 8 so I must make it work under Solaris 8)
    Here is a very simple code (main.cpp) you can compile/try on your Sun Solaris 8 workstation :
    #include <pthread.h>
    #include <stdio.h>
    #include <iostream.h>
    #include <unistd.h>
    pthread_mutex_t mutex;
    extern "C" void bigWorkerThr(void pClosure)
         while(1)
              if(0 != pthread_mutex_lock(&mutex)) exit(0);
              char str[5];
              strcpy(str, "test"); // short time operation
              if(0 != pthread_mutex_unlock(&mutex)) exit(0);
              //usleep(1);
         return(NULL);
    extern "C" void slowWorkerThr(void pClosure)
         while(1)
              sleep(1);
              if(0 != pthread_mutex_lock(&mutex)) exit(0);
              cerr << "HELLO WORLD" << endl; // display "HELLO WORLD" means it works
              if(0 != pthread_mutex_unlock(&mutex)) exit(0);
         return(NULL);
    int main()
         cerr << "STARTING ..." << endl;
         pthread_mutex_init(&mutex, NULL);
         pthread_t bigWorkerThrID;
         if(0 != pthread_create(&bigWorkerThrID, NULL, bigWorkerThr, NULL)) exit(0); // big worker
         pthread_t slowWorkerThrID;
         if(0 != pthread_create(&slowWorkerThrID, NULL, slowWorkerThr, NULL)) exit(0); // slow worker
         void *res = NULL;
         pthread_join(slowWorkerThrID, &res);
         pthread_join(bigWorkerThrID, &res);
    Here is my compiling command and environment:
    # $ uname -a
    # SunOS mscorail 5.8 Generic_117350-45 sun4u sparc SUNW,Sun-Fire-V210
    (SunFire V210 (2 x 1336 MHz) with 4 Go of memory)
    # $ CC -V
    # CC: Sun C++ 5.8 2005/10/13
    # $ CC -mt main.cpp -o main

    The way you are programming the locks is incorrect. You cannot depend on
    the "unlock" statement to cause the other thread to run. The most EFFICIENT way for the OS to run a threaded program, is to keep running the same
    thread until it must block for some reason. If you want two threads to
    hand off back and forth to share a resource, you have to add explicit
    variables or extra synchronization to directly cause the threads take
    turns the way you want.
    --chris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Pthreads on Solaris 64 bit

    Hi all;
    This is kinda of a vague question but maybe ye can help.
    I am trying to compile a process using pthreads and in the link line and orginally i got a problem with sigwait but this flag -D_POSIX_PTHREAD_SEMANTICS sorted it. Now i am getting a problem with SIGKILL so i was wondering is their any other flags i need to set in relation to pthreads?
    Thanks!

    What kind of problem you get with SIGKILL?
    As for posix stuff - there is controlling macro POSIXC_SOURCE.
    Taking a look at /usr/include/sys/feature_tests.h:
    *      Values of _POSIX_C_SOURCE
    *              undefined       not a POSIX compilation
    *                      1       POSIX.1-1990 compilation
    *                      2       POSIX.2-1992 compilation
    *                199309L       POSIX.1b-1993 compilation (Real Time)
    *                199506L       POSIX.1c-1995 compilation (POSIX Threads)
    */It looks like you might want to set it to 199506L.
    regards,
    __Fedor.

  • Request for discussion about pthread's mutexes

    Hello,
    A case looks simple. Two threads can communicate with device using ethernet interface. Because protocol's manners only one can use the channel. To provide exclusive execution I used a pthread mutex.
    An error is situation when thread A waits on mutex (thread B owns it), but when thread B releases it, thread A still sleeps. After a tick thread B again trying to lock mutex and succeed. Thread A sleeps on mutex until thread B calls function pthread_join with thread A id. Probability of error increases with speed of device. If more packets in second are sent and received, the error almost always happen.
    I spent many hours with e.g. truss and I am almost sure that it isn't implementation problem. I haven't ideas what do I wrong.
    The error not depend on what type mutexes are (default or recursive), libs (pthread, thread or alternative thread), if thread is bound with lwp or unbound.
    Threads: A and B are created with the same way, i.e. with the same priority and attributes.
    I use Solaris 8 with recommended patch and gcc.
    Any ideas will be welcome.
    Thanks
    Marcin

    I don't like the idea of using pthread_join in thread
    B to wait for thread A.
    Please read the
    "Multithreaded Programming Guide"
    http://docs.sun.com/db/doc/806-6867
    and
    "Multithreading in the Solaris Operating Environment"
    http://wwws.sun.com/software/whitepapers/solaris9/multithread.pdf
    They are must for all Solaris mt software developers.

  • [SOLVED: corrupted FS] Why is pthread not found?

    Hi,
    I'm sure this is a stupid problem since i'm way too tired, but i have to get this fixed. I've been looking on google for hours, and i can't seem to find my answer.
    I'm trying to build player/stage. I tried both the player-svn package in AUR and manually compiling from a svn checkout.
    My problem is that it cannot seem to find pthread.h with its cmake. I tried everything i could think of to link to it. phtread.h exists in /usr/include and boost is installed. Yet, cmake can't see to find it.
    I have installed base-devel and everything i could think of, but it still fails.
    Any thoughts would be greatly appreciated
    Thanks,
    Jni
    Last edited by jni (2011-03-27 06:33:55)

    I am sorry, i found the issue
    The USB key the OS is on is completly corrupted. It died
    Sorry about that.
    PS: sorry about that typo #include, obviously lol (i re-typed the code, my test file did have an #include)

  • Flash::media::Sound pthread problem

    When i start these two thread together the application freeze.
    Each thread on its own works !
    #include <pthread.h>
    #include <Flash++.h>
    using namespace AS3::ui;
    pthread_t audiothread;
    pthread_t tickThread;
    static var sampleDataEventListener(void *arg, var as3Args)
        flash::events::SampleDataEvent event = var(as3Args[0]);
        flash::utils::ByteArray data = event->data;
        printf("info: sampleDataEventListener write zero---\n");
         for ( unsigned int c = 0; c < 8192; c++ )
            data->writeFloat(0.0f);
        return internal::_undefined;
    static void *sampleDataThreadProc(void *arg)
        printf("Create sound object\n");
        flash::media::Sound sound = flash::media::Sound::_new(internal::_null, internal::_null);
        sound->addEventListener(flash::events::SampleDataEvent::SAMPLE_DATA, Function::_new(sampleDataEventListener, NULL), false, 0, false);
        sound->play(0, 0, internal::_null);
        AS3_GoAsync();
        printf("Error: GoAsync returned!\n");
        return NULL;
    ** Tick thread
    void *tickThreadProc(void *colorArg) {
        printf("TickThread start\n");
        int i = 0;
        while(i < 20)
            usleep(80*1000);
            printf("tick\n");
            i++;
        printf("TickThread done!!\n");
        return NULL;
    ** main method
    int main()
        printf("init console\n");
        pthread_create(&audiothread, NULL, sampleDataThreadProc, NULL);
        pthread_create(&tickThread, NULL, tickThreadProc, NULL);
        AS3_GoAsync();
        return 0;
    The application freeze with the output:
    init console
    Create sound object
    TickThread start
    tick
    tick
    tick
    My build call is:
    "$(FLASCC)/usr/bin/g++" $(BASE_CFLAGS) flash++ui.cpp -lAS3++ -lFlash++ -symbol-abc=Console.abc -pthread -O1 -swf-size=500x500 -emit-swf -o flashui.swf
    My console.as can be found here:  http://pastebin.com/ngkbcdYC
    I tried to init the console in both ways (CModule.startAsync(this) and CModule.startBackground(this, new <String>[], new <String>[]))  which doesn't make a diffrence.
    I also tried to set the -swf-version=18 parameter, but it doesn't make a difference, too.
    Anyone has an idea what is wrong ?
    Thanks !

    It may be that the calls to printf() are causing the problem. The printf() function may or may not be thread-safe or reentrant, depending on the system. Perhaps you might enable printf in only one of the threads, run it, and then enable it only in the other thread, and see what happens (easy test to make). If you are more ambitious, you could wrap the printf calls in a mutex. Generally, some folks recommend doing an explicit flush...

  • Pthreads not free'ing stack when terminated

    Hello,
    I have a simple program that initializes itself as a demon and then sits on a socket waiting for requests. For each request it gets on the socket the demon starts a pthread. The thread does a pthread_detach() and then does it's job (hello world) and then exits.
    I notice that the memory footprint (via 'top') of my demon is growing and growing. I put a printf of a automatic variable in my thread function and it seems that the stack for the threads are not being released when the thread exits. And so my process grows and grows until it's a problem.
    Can you please explain this behavior? I'd like to avoid having to allocate and manage the stack space for the threads myself.
    Thank you,
    [email protected]
    617-621-5310

    I want to correct my last post because the automatic variable address in my printf does stay the same. So the stack does seem to get released when the detached thread terminates. So why does the process size continue to grow in memory?

  • Flash builder4.7 Crossbridge_1.0.1 flex_sdk_4.6  unable to combine pthread and as file together.

    flash builder4.7 Crossbridge_1.0.1 flex_sdk_4.6 
    i made a swc according the sample of 09_Pthreads of the Crossbridge_1.0.1. the swf could generate and it could not run.
    the sample under 09_Pthreads directory also could not run. it is make swctest flag. it could generate pthread_swc1.swf and pthread_swc2.swf two files.
    pthread_swc1.swf works fine. but pthread_swc2.swf could not run.

    problem sovled. it is crossbrige's bug.
    Problem using sample pthread.swc in a Flex project

  • ERROR: The pthread library is unknown.

    I know redhat 8.0 is not a supported platform for JRockit 8.1. Indeed, when I try
    to start JRockit I get an "ERROR: The pthread library is unknown."
    Setting and unsetting LD_ASSUME_KERNEL doesn't help.
    Anyone know how to run JRockit 8.1 on a redhat 8.0 linux box (kernel 2.4.18, glibc
    2.3.2) ?

    I found a work-around:
    Download glibc-2.2.5-40.i686.rpm from Redhat 7.3 updates.
    The file is available at any redhat mirror:
    ftp://ftp.funet.fi/pub/Linux/mirrors/redhat/redhat/linux/updates/7.3/en/os/i686/glibc-2.2.5-40.i686.rpm
    Then extract the contents of the rpm (don't install it!) to a separate
    directory.
    directions:
    cd /usr/local
    mkdir glibc-2.2.5-40
    cd glibc-2.2.5-40
    rpm2cpio ~/glibc-2.2.5-40.i686.rpm | cpio -iumdv
    Now glibc-2.2.5-40 is installed in /usr/local/glibc-2.2.5-40 directory
    then before using JRockit (in a script etc.)
    export LD_LIBRARY_PATH=/usr/local/glibc-2.2.5-40/lib:\
    /usr/local/glibc-2.2.5-40/lib/i686:/usr/local/glibc-2.2.5-40/usr/lib/gconv
    export PATH=/usr/jrockit/7.0/1.4.0/bin:$PATH
    After this jrockit should work on Redhat 8.0!
    BR
    Lari

  • Pthread threads with OCI

    Hi.
    How can I use pthread threads with OCI?
    When I'm just trying to call OCIEnvCreate I get segfault.

    I have 10 threads with the following code:
    OCIEnv *envhp;
    OCIServer *srvhp;
    OCISvcCtx *svchp;
    OCISession *authp;
    OCIStmt *stmthp = (OCIStmt *) NULL;
    OCIError *errhp;
        /* Initialize the mode to be the threaded and object environment */
        if (OCIEnvCreate((OCIEnv **) &envhp, OCI_THREADED | OCI_OBJECT, (dvoid *)0,
                         0, 0, 0, (size_t) 0, (dvoid **) 0)) {
            printf("%s\n", "FAILED: OCIEnvCreate()");
        /* Allocate a service handle */
        if (OCIHandleAlloc((dvoid *) envhp, (dvoid **) &svchp,
                           OCI_HTYPE_SVCCTX, (size_t) 0, (dvoid **) 0)) {
            syslog(LOG_ERR, "FAILED: OCIHandleAlloc() on svchp\n");
        /* Allocate an error handle */
        if (OCIHandleAlloc((dvoid *) envhp, (dvoid **) &errhp,
                           OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0)) {
            syslog(LOG_ERR, "FAILED: OCIHandleAlloc() on errhp\n");
        /* Allocate a server handle */
        if (OCIHandleAlloc((dvoid *) envhp, (dvoid **) &srvhp,
                           OCI_HTYPE_SERVER, (size_t) 0, (dvoid **) 0)) {
            syslog(LOG_ERR, "FAILED: OCIHandleAlloc() on srvhp\n");
        /* Allocate a authentication handle */
        if (OCIHandleAlloc((dvoid *) envhp, (dvoid **) &authp,
                           OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0)) {
            syslog(LOG_ERR, "FAILED: OCIHandleAlloc() on authp\n");
        /* Attach to the database server */
        if (OCIServerAttach(srvhp, errhp, (text *)dbname,
                            strlen(dbname), 0)) {
            syslog(LOG_ERR, "FAILED: OCIServerAttach()\n");
        /* Set the server handle in the service handle */
        if (OCIAttrSet((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX,
                       (dvoid *) srvhp, (ub4) 0, (ub4) OCI_ATTR_SERVER, errhp)) {
            syslog(LOG_ERR, "FAILED: OCIAttrSet() server attribute\n");
        /* Logon to the server and begin a session */
        /* Set attributes in the authentication handle */
        if (OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,
                       (dvoid *) dbuser, (ub4) strlen(dbuser),
                       (ub4) OCI_ATTR_USERNAME, errhp)) {
            syslog(LOG_ERR, "FAILED: OCIAttrSet() userid\n");
        if (OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,
                       (dvoid *) dbpass, (ub4) strlen(dbpass),
                       (ub4) OCI_ATTR_PASSWORD, errhp)) {
            syslog(LOG_ERR, "FAILED: OCIAttrSet() passwd\n");
        if (OCISessionBegin(svchp, errhp, authp, OCI_CRED_RDBMS, OCI_DEFAULT)) {
            syslog(LOG_ERR, "FAILED: OCIAttrSet() passwd\n");
        /* Set the authentication handle in the Service handle */
        if (OCIAttrSet((dvoid *) svchp, (ub4) OCI_HTYPE_SVCCTX,
                       (dvoid *) authp, (ub4) 0, (ub4) OCI_ATTR_SESSION, errhp)) {
            syslog(LOG_ERR, "FAILED: OCIAttrSet() session\n");
            sb4 errcode = 0;
            text errbuf[1024];
            (void) OCIErrorGet((dvoid *)errhp, (ub4) 1, (text *) NULL, &errcode,
                               errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
            syslog(LOG_ERR, "Error - %.*s\n", 1024, errbuf);
        /* Allocate a statement handle */
        if (OCIHandleAlloc((dvoid *)envhp, (dvoid **) &stmthp,
                           (ub4)OCI_HTYPE_STMT, (CONST size_t) 0, (dvoid **) 0)) {
            syslog(LOG_ERR, "FAILED: alloc statement handle\n");
    ...What did I do wrong?

  • Socket problems when using pthreads

    When using pthreads, any calls to accept inside a thread other than main returns no remote address. While I don't believe this a POSIX standards violation, it is still somewhat inconvenient as it means main must be the only thread accepting connections if a log of remote hosts is to be maintained.
    If anyone has a solution to this problem please email me with a fix.
    Thanks.

    Hi,
    I have a Multithreaded application with Stream Socket.After Calling listen,the socket state is BOUND.What is mean by BOUND? How I can change this state to Listen?The server is not accepting the connection?
    I am looking forward some help regard with this issue.If you know solutions please mail me.[[email protected]]

Maybe you are looking for