小编Vij*_*har的帖子

Timespec重新定义错误

使用Visual Studio 2015在C中执行Pthread程序时,出现以下错误:

Error C2011 'timespec': 'struct' type redefinition
Run Code Online (Sandbox Code Playgroud)

以下是我的代码:

#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>


void *calculator(void *parameter);

int main(/*int *argc,char *argv[]*/)
{
    pthread_t thread_obj;
    pthread_attr_t thread_attr;
    char *First_string = "abc"/*argv[1]*/;
    pthread_attr_init(&thread_attr);
        pthread_create(&thread_obj,&thread_attr,calculator,First_string);

}
void *calculator(void *parameter)
{
    int x=atoi((char*)parameter);
    printf("x=%d", x);
}
Run Code Online (Sandbox Code Playgroud)

pthread.h头文件包含有关的timespec下面的代码:

#if !defined(HAVE_STRUCT_TIMESPEC)
#define HAVE_STRUCT_TIMESPEC
#if !defined(_TIMESPEC_DEFINED)
#define _TIMESPEC_DEFINED
struct timespec {
        time_t tv_sec;
        long tv_nsec;
};
#endif /* _TIMESPEC_DEFINED */
#endif /* HAVE_STRUCT_TIMESPEC */
Run Code Online (Sandbox Code Playgroud)

我使用的其他头文件timespec都没有使用struct,因此没有机会重新定义.由于已从pthread opensource网站下载,因此不存在损坏的头文件的可能性.

c windows pthreads visual-studio timespec

11
推荐指数
1
解决办法
2万
查看次数

Timespec:struct type错误c2011

使用Visual Studio 2015在C中执行Pthread程序时出现以下错误

错误C2011'timespec':'struct'类型重新定义

以下是我的代码:

#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>


void *calculator(void *parameter);

int main(/*int *argc,char *argv[]*/)
{
    pthread_t thread_obj;
    pthread_attr_t thread_attr;
    char *First_string = "abc"/*argv[1]*/;
    pthread_attr_init(&thread_attr);
        pthread_create(&thread_obj,&thread_attr,calculator,First_string);

}
void *calculator(void *parameter)
{
    int x=atoi((char*)parameter);
    printf("x=%d", x);
}
Run Code Online (Sandbox Code Playgroud)

c pthreads visual-studio

7
推荐指数
2
解决办法
5773
查看次数

由于GUID重复,无法与会话org.hibernate.exception.ConstraintViolationException同步数据库状态

我使用休眠模式使用自动生成的GUID将数据插入到表中,但是有时会由于GUID重复而导致插入失败。

例如:

在Logs中,通过打印重复的GUID'0500edac-0074-4324-3436-31444231342d',在前两次尝试中插入失败。花费的时间如下

     1st attempt :08-27-2018 04:27:00.012,

     2nd attempt :08-27-2018 04:27:01.024,

     3rd attempt was not logged ,as it was successful
Run Code Online (Sandbox Code Playgroud)

但是在数据库中,我看到在'08 -27-2018 04:27:01.054'创建的GUID为'0500edac-0074-4324-3436-31444231342d'的行

所以我不确定为什么我会在前两次尝试中获得异常,然后成功地将其插入到第3次。

SQL表属性:我有一个名为“ DataHistory”的SQL Server表,其中的列名为

"DataHistoryGuid" with the following properties uniqueidentifier,ROWGUIDCOL,Primary Key column,newsequentialid .
Run Code Online (Sandbox Code Playgroud)

Hibernate属性:我正在使用hibernate将数据存储在该表中,对于GUID列,我正在使用

<id name="dataHistoryGuid" type="java.util.UUID" >
        <column name="DataHistoryGuid"/>
        <generator class="guid"/>
    </id>
Run Code Online (Sandbox Code Playgroud)

以下是异常跟踪:

[event.def.AbstractFlushingEventListener:performExecutions:324]
Could not synchronize database state with session 
org.hibernate.exception.ConstraintViolationException: could not 
 insert: [com.testProj.dataprocessor.model.sql.SqlDataHistory] 
  at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94) 
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2295) 
  at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688) 
  at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) 
  at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) 
  at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263) 
  at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167) 
  at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) 
  at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) …
Run Code Online (Sandbox Code Playgroud)

java sql sql-server hibernate

7
推荐指数
1
解决办法
226
查看次数

基于Java中字符串的第n次出现拆分字符串

如何根据分隔符的第 n 次(例如:第二次)出现拆分字符串。而除了第 n 次出现之外,应保留所有其他分隔符

输入/输出:

 String name="This is my First Line";
 int delimiter=" ";
 int count=3;//This is a dynamic value
Run Code Online (Sandbox Code Playgroud)

开/关:

String firstpart=This is my
String Secondpart=First Line
Run Code Online (Sandbox Code Playgroud)

java regex string

2
推荐指数
1
解决办法
2203
查看次数

标签 统计

c ×2

java ×2

pthreads ×2

visual-studio ×2

hibernate ×1

regex ×1

sql ×1

sql-server ×1

string ×1

timespec ×1

windows ×1